diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 5d6cd8c..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,32 +0,0 @@ -version: 2 - -workflows: - version: 2 - workflow: - jobs: - - test - -jobs: - test: - docker: - - image: circleci/php:7.4 - - steps: - - checkout - - - run: sudo apt update - - run: sudo docker-php-ext-install zip - - - restore_cache: - keys: - - v1-dependencies-{{ checksum "composer.json" }} - - v1-dependencies- - - - run: composer install -n --prefer-dist - - - save_cache: - key: v1-dependencies-{{ checksum "composer.json" }} - paths: - - ./vendor - - - run: ./vendor/bin/phpunit diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..6e653c2 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: [eymengunay, razvanphp] diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..2c3a577 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,55 @@ +name: Code Quality + +on: + push: + branches: + - master + paths-ignore: + - README.md + pull_request: + workflow_dispatch: + +jobs: + phpcs: + runs-on: ubuntu-latest + name: PHP_CodeSniffer + steps: + - uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + tools: cs2pr, phpcs + + - name: Run phpcs + run: phpcs -q --report=checkstyle . | cs2pr + + phpstan: + runs-on: ubuntu-latest + name: PHPStan + steps: + - uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + tools: phpstan + + - name: Get composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache dependencies + uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install dependencies + run: composer install --prefer-dist + + - name: Run PHPStan + run: phpstan analyse --level=3 src tests diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..6950d47 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,46 @@ +name: PHPUnit + +on: + push: + branches: + - master + paths-ignore: + - README.md + pull_request: + workflow_dispatch: + +jobs: + run: + runs-on: ubuntu-latest + strategy: + matrix: + php-version: ['7.4', '8.0', '8.1', '8.2'] + name: PHP ${{ matrix.php-version }} + steps: + - uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + tools: composer:v2 + + - name: Setup problem matchers for PHPUnit + run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Get composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache dependencies + uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install dependencies + run: composer install --prefer-dist + + - name: Run PHPUnit + run: vendor/bin/phpunit --color=always \ No newline at end of file diff --git a/.gitignore b/.gitignore index f1927c0..a903869 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ vendor .idea/ +.phpunit.result.cache diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 67fcf60..2124ec7 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,151 +1,38 @@ +checks: + php: true + filter: - excluded_paths: - - ./tests - - ./www - paths: { } -before_commands: - - 'composer install --dev --prefer-source --no-interaction' -tools: - php_mess_detector: - enabled: true - extensions: - - php - filter: - excluded_paths: - - ./tests - - ./www - paths: { } - config: - ruleset: null - code_size_rules: - cyclomatic_complexity: false - npath_complexity: false - excessive_method_length: false - excessive_class_length: false - excessive_parameter_list: false - excessive_public_count: false - too_many_fields: false - too_many_methods: false - excessive_class_complexity: false - design_rules: - exit_expression: true - eval_expression: true - goto_statement: true - number_of_class_children: false - depth_of_inheritance: false - coupling_between_objects: false - unused_code_rules: - unused_private_field: true - unused_local_variable: false - unused_private_method: false - unused_formal_parameter: false - naming_rules: - short_variable: false - long_variable: false - short_method: false - constructor_conflict: true - constant_naming: false - boolean_method_name: false - controversial_rules: - superglobals: true - camel_case_class_name: false - camel_case_property_name: false - camel_case_method_name: false - camel_case_parameter_name: false - camel_case_variable_name: false - path_configs: { } - php_cs_fixer: - enabled: true - config: - level: all - fixers: - indentation: false - linefeed: false - trailing_spaces: false - unused_use: false - phpdoc_params: false - visibility: false - return: false - short_tag: false - braces: false - include: false - php_closing_tag: false - extra_empty_lines: false - controls_spaces: false - elseif: false - eof_ending: false - extensions: - - php - filter: - excluded_paths: - - ./tests - - ./www - paths: { } - php_code_sniffer: - enabled: true - config: - sniffs: - generic: { php: { disallow_short_open_tag_sniff: true, sapi_usage_sniff: false, no_silenced_errors_sniff: false, deprecated_functions_sniff: true, upper_case_constant_sniff: false, closing_php_tag_sniff: false, forbidden_functions_sniff: false, lower_case_constant_sniff: false, character_before_php_opening_tag_sniff: true, lower_case_keyword_sniff: false }, functions: { function_call_argument_spacing_sniff: true, opening_function_brace_kernighan_ritchie_sniff: false, opening_function_brace_bsd_allman_sniff: false, call_time_pass_by_reference_sniff: false }, code_analysis: { unused_function_parameter_sniff: false, for_loop_with_test_function_call_sniff: true, unconditional_if_statement_sniff: false, empty_statement_sniff: true, unnecessary_final_modifier_sniff: true, for_loop_should_be_while_loop_sniff: false, useless_overriding_method_sniff: true, jumbled_incrementer_sniff: true }, classes: { duplicate_class_name_sniff: false }, white_space: { disallow_tab_indent_sniff: false, scope_indent_sniff: false, disallow_space_indent_sniff: false }, formatting: { multiple_statement_alignment_sniff: false, no_space_after_cast_sniff: false, space_after_cast_sniff: false, disallow_multiple_statements_sniff: false }, files: { one_interface_per_file_sniff: false, end_file_newline_sniff: false, line_length_sniff: false, inline_html_sniff: false, byte_order_mark_sniff: false, end_file_no_newline_sniff: false, one_class_per_file_sniff: false, line_endings_sniff: false }, version_control: { subversion_properties_sniff: false }, commenting: { fixme_sniff: false, todo_sniff: false }, control_structures: { inline_control_structure_sniff: false }, strings: { unnecessary_string_concat_sniff: false }, naming_conventions: { camel_caps_function_name_sniff: false, constructor_name_sniff: false, upper_case_constant_name_sniff: false }, metrics: { cyclomatic_complexity_sniff: false, nesting_level_sniff: false } } - psr2: { classes: { property_declaration_sniff: true, class_declaration_sniff: false }, methods: { method_declaration_sniff: false }, namespaces: { namespace_declaration_sniff: false, use_declaration_sniff: false }, files: { end_file_newline_sniff: false }, control_structures: { control_structure_spacing_sniff: false, switch_declaration_sniff: false, else_if_declaration_sniff: false } } - psr1: { classes: { class_declaration_sniff: false }, files: { side_effects_sniff: true } } - zend: { debug: { code_analyzer_sniff: false }, files: { closing_tag_sniff: false }, naming_conventions: { valid_variable_name_sniff: false } } - squiz: { scope: { static_this_usage_sniff: true, method_scope_sniff: true, member_var_scope_sniff: true }, code_analysis: { empty_statement_sniff: false }, classes: { lowercase_class_keywords_sniff: false, valid_class_name_sniff: false, class_file_name_sniff: false, self_member_reference_sniff: true, class_declaration_sniff: false }, arrays: { array_bracket_spacing_sniff: false, array_declaration_sniff: false }, objects: { object_instantiation_sniff: false }, white_space: { logical_operator_spacing_sniff: false, language_construct_spacing_sniff: false, operator_spacing_sniff: false, control_structure_spacing_sniff: false, function_opening_brace_space_sniff: false, function_spacing_sniff: false, superfluous_whitespace_sniff: false, member_var_spacing_sniff: false, scope_closing_brace_sniff: false, scope_keyword_spacing_sniff: false, function_closing_brace_space_sniff: false, semicolon_spacing_sniff: false, cast_spacing_sniff: false, object_operator_spacing_sniff: false }, php: { disallow_comparison_assignment_sniff: false, disallow_size_functions_in_loops_sniff: false, heredoc_sniff: false, disallow_ob_end_flush_sniff: false, inner_functions_sniff: false, forbidden_functions_sniff: false, eval_sniff: false, lowercase_p_h_p_functions_sniff: false, discouraged_functions_sniff: false, embedded_php_sniff: false, commented_out_code_sniff: false, disallow_inline_if_sniff: false, disallow_multiple_assignments_sniff: false, global_keyword_sniff: false, non_executable_code_sniff: true }, formatting: { operator_bracket_sniff: false }, functions: { lowercase_function_keywords_sniff: false, global_function_sniff: false, function_duplicate_argument_sniff: false, multi_line_function_declaration_sniff: false, function_declaration_argument_spacing_sniff: false, function_declaration_sniff: false }, files: { file_extension_sniff: false }, commenting: { inline_comment_sniff: false, post_statement_comment_sniff: false, class_comment_sniff: false, doc_comment_alignment_sniff: false, block_comment_sniff: false, function_comment_sniff: false, function_comment_throw_tag_sniff: false, variable_comment_sniff: false, empty_catch_comment_sniff: false, file_comment_sniff: false, long_condition_closing_comment_sniff: false, closing_declaration_comment_sniff: false }, control_structures: { control_signature_sniff: false, lowercase_declaration_sniff: false, inline_if_declaration_sniff: false, for_each_loop_declaration_sniff: false, for_loop_declaration_sniff: false, switch_declaration_sniff: false, else_if_declaration_sniff: false }, strings: { echoed_strings_sniff: false, concatenation_spacing_sniff: false, double_quote_usage_sniff: false }, naming_conventions: { valid_function_name_sniff: false, valid_variable_name_sniff: false, constant_case_sniff: false }, operators: { increment_decrement_usage_sniff: false, valid_logical_operators_sniff: false, comparison_operator_usage_sniff: false } } - my_source: { php: { return_function_value_sniff: false, eval_object_factory_sniff: false }, debug: { debug_code_sniff: false }, commenting: { function_comment_sniff: false } } - pear: { classes: { class_declaration_sniff: false }, white_space: { object_operator_indent_sniff: false, scope_indent_sniff: false, scope_closing_brace_sniff: false }, formatting: { multi_line_assignment_sniff: false }, functions: { function_call_signature_sniff: false, function_declaration_sniff: false, valid_default_value_sniff: false }, files: { including_file_sniff: false }, commenting: { inline_comment_sniff: false, class_comment_sniff: false, function_comment_sniff: false, file_comment_sniff: false }, control_structures: { control_signature_sniff: false, multi_line_condition_sniff: false }, naming_conventions: { valid_function_name_sniff: false, valid_variable_name_sniff: false, valid_class_name_sniff: false } } - wordpress: { arrays: { array_declaration_sniff: false }, classes: { valid_class_name_sniff: false }, files: { file_name_sniff: false }, formatting: { multiple_statement_alignment_sniff: false }, functions: { function_call_signature_sniff: false, function_declaration_argument_spacing_sniff: false }, naming_conventions: { valid_function_name_sniff: false }, objects: { object_instantiation_sniff: false }, php: { discouraged_functions_sniff: false }, strings: { double_quote_usage_sniff: false }, white_space: { control_structure_spacing_sniff: false, operator_spacing_sniff: false, php_indent_sniff: false }, xss: { escape_output_sniff: false } } - tab_width: 0 - encoding: utf8 - standard: custom - extensions: - - php - filter: - excluded_paths: - - ./tests - - ./www - paths: { } - sensiolabs_security_checker: - enabled: true - filter: - excluded_paths: - - ./tests - - ./www - paths: { } - php_code_coverage: - enabled: true - test_command: phpunit - config_path: null - only_changesets: false - filter: - excluded_paths: - - ./tests - - ./www - paths: { } - php_cpd: - excluded_dirs: - - ./tests - - ./www - min_lines: '10' - enabled: true - names: - - '*.php' - min_tokens: 70 - filter: - excluded_paths: - - ./tests - - ./www - paths: { } - php_loc: - excluded_dirs: - - ./tests - - ./www - enabled: true - names: - - '*.php' -changetracking: - bug_patterns: - - '\bfix(?:es|ed)?\b' - feature_patterns: - - '\badd(?:s|ed)?\b' - - '\bimplement(?:s|ed)?\b' -after_commands: { } -artifacts: { } + paths: + - src/* + - tests/* + excluded_paths: + - www/* + +build: + image: default-bionic + + environment: + php: + version: 8.2 + ini: + xdebug.mode: coverage + + nodes: + analysis: + tests: + override: + - php-scrutinizer-run + + phpunit: + dependencies: + override: + - composer self-update + - composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + + tests: + override: + - command: ./vendor/bin/phpunit --coverage-clover ./coverage.xml + on_node: 1 + coverage: + file: coverage.xml + format: php-clover \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b987427..0000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -dist: trusty - -language: php - -php: - - 5.4 - - 5.5 - - 5.6 - - 7.0 - -before_script: - - composer install --dev --prefer-source - -script: phpunit diff --git a/README.md b/README.md index f9e121d..f8e578c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # PHP PASSBOOK LIBRARY -[![CircleCI](https://circleci.com/gh/eymengunay/php-passbook.svg?style=shield)](https://circleci.com/gh/eymengunay/php-passbook) +[![Code Coverage](https://scrutinizer-ci.com/g/eymengunay/php-passbook/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/eymengunay/php-passbook/?branch=master) +[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/eymengunay/php-passbook/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/eymengunay/php-passbook/?branch=master) +[![PHPUnit](https://github.com/eymengunay/php-passbook/actions/workflows/test.yml/badge.svg)](https://github.com/eymengunay/php-passbook/actions/workflows/test.yml) [![Total Downloads](https://img.shields.io/packagist/dt/eo/passbook.svg)](https://packagist.org/packages/eo/passbook) [![Latest Stable Version](https://img.shields.io/packagist/v/eo/passbook.svg)](https://packagist.org/packages/eo/passbook) @@ -49,7 +51,7 @@ This example will create a pass of type Ticket and will save the pkpass file in * [Obtain a Pass Type Identifier and Team Identifier from Apple](#obtaining-the-pass-type-identifier-and-team-id) * Get an icon (29x29 png file) for the pass * Specify a name for your organization -* Specify the output path where the pass will be saved
 +* Specify the output path where the pass will be saved ```php =7.4", "ext-zip": "*", @@ -26,7 +31,9 @@ }, "require-dev": { "phpunit/phpunit": "^9.0", - "nunomaduro/phpinsights": "dev-master" + "nunomaduro/phpinsights": "dev-master", + "squizlabs/php_codesniffer": "3.*", + "phpstan/phpstan": "^1.10" }, "autoload": { "psr-4": { diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..bc35bf9 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + /vendor/* + + diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f8e951a..9481942 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,8 +1,7 @@ + - - - + - + - - - tests/Passbook/Tests/ - - + + + tests/Passbook/Tests/ + + - - - src/Passbook/ - - - \ No newline at end of file + + + src/Passbook/ + + + diff --git a/src/Passbook/ArrayableInterface.php b/src/Passbook/ArrayableInterface.php index 3285ab8..9374b00 100644 --- a/src/Passbook/ArrayableInterface.php +++ b/src/Passbook/ArrayableInterface.php @@ -4,12 +4,10 @@ interface ArrayableInterface { - /** * Get the instance as an array. * * @return array */ - public function toArray(); - -} \ No newline at end of file + public function toArray(); +} diff --git a/src/Passbook/Certificate/P12Interface.php b/src/Passbook/Certificate/P12Interface.php index efe2a60..3784b13 100644 --- a/src/Passbook/Certificate/P12Interface.php +++ b/src/Passbook/Certificate/P12Interface.php @@ -35,7 +35,7 @@ public function getPassword(); /** * Sets p12 password * - * @param string + * @param string $password */ public function setPassword($password); } diff --git a/src/Passbook/Exception/PassInvalidException.php b/src/Passbook/Exception/PassInvalidException.php index 27dcd0b..e209c59 100644 --- a/src/Passbook/Exception/PassInvalidException.php +++ b/src/Passbook/Exception/PassInvalidException.php @@ -21,7 +21,7 @@ class PassInvalidException extends \RuntimeException public function __construct($message = '', array $errors = null) { parent::__construct($message); - $this->errors = $errors ? $errors : array(); + $this->errors = $errors ? $errors : []; } /** diff --git a/src/Passbook/Pass.php b/src/Passbook/Pass.php index db61d9f..ab8cae1 100644 --- a/src/Passbook/Pass.php +++ b/src/Passbook/Pass.php @@ -65,7 +65,7 @@ class Pass implements PassInterface /** * Pass structure * - * @var Structure + * @var StructureInterface */ protected $structure; @@ -74,7 +74,7 @@ class Pass implements PassInterface * * @var ImageInterface[] */ - protected $images = array(); + protected $images = []; /** * Beacons where the pass is relevant. @@ -86,11 +86,10 @@ class Pass implements PassInterface /** * NFC where the pass is relevant. * - * @var array + * @var NfcInterface[] */ protected $nfc = []; - /** * A list of iTunes Store item identifiers (also known as Adam IDs) for the * associated apps. @@ -186,8 +185,6 @@ class Pass implements PassInterface */ protected $logoText; - - /** * If true, the strip image is displayed without a shine effect. * @@ -257,12 +254,12 @@ class Pass implements PassInterface */ protected $appLaunchURL; - /** - * Pass userInfo - * - * @var mixed - */ - protected $userInfo; + /** + * Pass userInfo + * + * @var mixed + */ + protected $userInfo; /** * @@ -271,7 +268,7 @@ class Pass implements PassInterface * @var bool * */ - protected bool $sharingProhibited = false; + protected bool $sharingProhibited = false; public function __construct($serialNumber, $description) { @@ -289,7 +286,7 @@ public function toArray() $array[$this->getType()] = $this->getStructure()->toArray(); } - $properties = array( + $properties = [ 'serialNumber', 'description', 'formatVersion', @@ -315,9 +312,9 @@ public function toArray() 'voided', 'appLaunchURL', 'associatedStoreIdentifiers', - 'userInfo', + 'userInfo', 'sharingProhibited' - ); + ]; foreach ($properties as $property) { $method = 'is' . ucfirst($property); if (!method_exists($this, $method)) { @@ -539,6 +536,7 @@ public function getBeacons() public function addNfc(NfcInterface $nfc) { $this->nfc[] = $nfc; + return $this; } @@ -550,7 +548,6 @@ public function getNfc() return $this->nfc; } - /** * {@inheritdoc} */ @@ -599,15 +596,15 @@ public function setBarcode(BarcodeInterface $barcode) } /** - * {@inheritdoc} + * @deprecated please use addNfc() instead. */ - public function setNfc(NfcInterface $nfc) + public function setNfc(array $nfc) { $this->nfc = $nfc; + return $this; } - /** * {@inheritdoc} */ @@ -890,31 +887,33 @@ public function getAppLaunchURL() return $this->appLaunchURL; } - /** - * {@inheritdoc} - */ - public function setUserInfo($userInfo) { - $this->userInfo = $userInfo; + /** + * {@inheritdoc} + */ + public function setUserInfo($userInfo) + { + $this->userInfo = $userInfo; - return $this; - } + return $this; + } - /** - * {@inheritdoc} - */ - public function getUserInfo() { - return $this->userInfo; - } + /** + * {@inheritdoc} + */ + public function getUserInfo() + { + return $this->userInfo; + } - public function setSharingProhibited(bool $value): self + public function setSharingProhibited(bool $value): self { - $this->sharingProhibited = $value; + $this->sharingProhibited = $value; - return $this; + return $this; } - public function getSharingProhibited(): bool { - return $this->sharingProhibited; + public function getSharingProhibited(): bool + { + return $this->sharingProhibited; } - } diff --git a/src/Passbook/Pass/Barcode.php b/src/Passbook/Pass/Barcode.php index a77d032..6cef116 100644 --- a/src/Passbook/Pass/Barcode.php +++ b/src/Passbook/Pass/Barcode.php @@ -21,23 +21,23 @@ class Barcode implements BarcodeInterface /** * @var string */ - const TYPE_QR = 'PKBarcodeFormatQR'; + public const TYPE_QR = 'PKBarcodeFormatQR'; /** * @var string */ - const TYPE_PDF_417 = 'PKBarcodeFormatPDF417'; + public const TYPE_PDF_417 = 'PKBarcodeFormatPDF417'; /** * @var string */ - const TYPE_AZTEC = 'PKBarcodeFormatAztec'; + public const TYPE_AZTEC = 'PKBarcodeFormatAztec'; /** * Available starting with iOS 9. * @var string */ - const TYPE_CODE_128 = 'PKBarcodeFormatCode128'; + public const TYPE_CODE_128 = 'PKBarcodeFormatCode128'; /** * Barcode format. Must be one of the following values: @@ -80,11 +80,11 @@ public function __construct($format, $message, $messageEncoding = 'iso-8859-1') public function toArray() { - $array = array( + $array = [ 'format' => $this->getFormat(), 'message' => $this->getMessage(), 'messageEncoding' => $this->getMessageEncoding() - ); + ]; if ($this->getAltText()) { $array['altText'] = $this->getAltText(); diff --git a/src/Passbook/Pass/BarcodeInterface.php b/src/Passbook/Pass/BarcodeInterface.php index 8dccbb7..dc554fb 100644 --- a/src/Passbook/Pass/BarcodeInterface.php +++ b/src/Passbook/Pass/BarcodeInterface.php @@ -23,7 +23,7 @@ interface BarcodeInterface extends ArrayableInterface /** * Sets barcode format * - * @param string + * @param string $format */ public function setFormat($format); @@ -37,7 +37,7 @@ public function getFormat(); /** * Sets barcode message * - * @param string + * @param string $message */ public function setMessage($message); @@ -51,7 +51,7 @@ public function getMessage(); /** * Sets barcode message encoding * - * @param string + * @param string $messageEncoding */ public function setMessageEncoding($messageEncoding); @@ -65,7 +65,7 @@ public function getMessageEncoding(); /** * Sets barcode alt text * - * @param string + * @param string $altText */ public function setAltText($altText); diff --git a/src/Passbook/Pass/Beacon.php b/src/Passbook/Pass/Beacon.php index 64afc54..9eb8fb8 100644 --- a/src/Passbook/Pass/Beacon.php +++ b/src/Passbook/Pass/Beacon.php @@ -52,9 +52,9 @@ public function __construct($proximityUUID) public function toArray() { - $array = array( + $array = [ 'proximityUUID' => $this->getProximityUUID() - ); + ]; if ($major = $this->getMajor()) { $array['major'] = $major; @@ -143,4 +143,3 @@ public function getRelevantText() return $this->relevantText; } } - diff --git a/src/Passbook/Pass/BeaconInterface.php b/src/Passbook/Pass/BeaconInterface.php index 32edd3c..8ed5ecc 100644 --- a/src/Passbook/Pass/BeaconInterface.php +++ b/src/Passbook/Pass/BeaconInterface.php @@ -23,7 +23,7 @@ interface BeaconInterface extends ArrayableInterface /** * Sets proximity UUID * - * @param string + * @param string $uuid */ public function setProximityUUID($uuid); @@ -37,7 +37,7 @@ public function getProximityUUID(); /** * Sets major * - * @param integer + * @param integer $major */ public function setMajor($major); @@ -51,7 +51,7 @@ public function getMajor(); /** * Sets minor * - * @param integer + * @param integer $minor */ public function setMinor($minor); @@ -72,9 +72,7 @@ public function getRelevantText(); /** * Sets relevant text * - * @param string + * @param string $relevantText */ public function setRelevantText($relevantText); - } - diff --git a/src/Passbook/Pass/DateField.php b/src/Passbook/Pass/DateField.php index 5ee23b2..755091c 100644 --- a/src/Passbook/Pass/DateField.php +++ b/src/Passbook/Pass/DateField.php @@ -16,14 +16,58 @@ * @package Passbook\Pass * @link https://developer.apple.com/library/ios/documentation/userexperience/Reference/PassKit_Bundle/Chapters/FieldDictionary.html#//apple_ref/doc/uid/TP40012026-CH4-SW1 * @author Florian Morello + * @phpcs:disable Generic.NamingConventions.UpperCaseConstantName */ class DateField extends Field { - const PKDateStyleNone = "PKDateStyleNone"; - const PKDateStyleShort = "PKDateStyleShort"; - const PKDateStyleMedium = "PKDateStyleMedium"; - const PKDateStyleLong = "PKDateStyleLong"; - const PKDateStyleFull = "PKDateStyleFull"; + /** + * @deprecated please use ::DATE_STYLE_NONE instead. + */ + public const PKDateStyleNone = 'PKDateStyleNone'; + + /** + * @deprecated please use ::DATE_STYLE_SHORT instead. + */ + public const PKDateStyleShort = 'PKDateStyleShort'; + + /** + * @deprecated please use ::DATE_STYLE_MEDIUM instead. + */ + public const PKDateStyleMedium = 'PKDateStyleMedium'; + + /** + * @deprecated please use ::DATE_STYLE_LONG instead. + */ + public const PKDateStyleLong = 'PKDateStyleLong'; + + /** + * @deprecated please use ::DATE_STYLE_FULL instead. + */ + public const PKDateStyleFull = 'PKDateStyleFull'; + + /** + * @var string + */ + public const DATE_STYLE_NONE = 'PKDateStyleNone'; + + /** + * @var string + */ + public const DATE_STYLE_SHORT = 'PKDateStyleShort'; + /** + * @var string + */ + public const DATE_STYLE_MEDIUM = 'PKDateStyleMedium'; + + /** + * @var string + */ + public const DATE_STYLE_LONG = 'PKDateStyleLong'; + + /** + * @var string + */ + public const DATE_STYLE_FULL = 'PKDateStyleFull'; /** * @var string @@ -147,7 +191,8 @@ public function getTimeStyle() * @param string|\DateTime $value * @return $this */ - public function setValue($value){ + public function setValue($value) + { if ($value instanceof \DateTime) { $value = $value->format('c'); } diff --git a/src/Passbook/Pass/Field.php b/src/Passbook/Pass/Field.php index 228941d..cefc165 100644 --- a/src/Passbook/Pass/Field.php +++ b/src/Passbook/Pass/Field.php @@ -14,48 +14,69 @@ /** * Field * @author Eymen Gunay + * @phpcs:disable Generic.NamingConventions.UpperCaseConstantName */ class Field implements FieldInterface { /** * @var string */ - const ALIGN_LEFT = 'PKTextAlignmentLeft'; + public const ALIGN_LEFT = 'PKTextAlignmentLeft'; /** * @var string */ - const ALIGN_CENTER = 'PKTextAlignmentCenter'; + public const ALIGN_CENTER = 'PKTextAlignmentCenter'; /** * @var string */ - const ALIGN_RIGHT = 'PKTextAlignmentRight'; + public const ALIGN_RIGHT = 'PKTextAlignmentRight'; /** * @var string */ - const ALIGN_NATURAL = 'PKTextAlignmentNatural'; + public const ALIGN_NATURAL = 'PKTextAlignmentNatural'; + + /** + * @deprecated please use ::DATA_DETECTOR_TYPE_PHONE_NUMBER instead. + */ + public const PKDataDetectorTypePhoneNumber = 'PKDataDetectorTypePhoneNumber'; + + /** + * @deprecated please use ::DATA_DETECTOR_TYPE_LINK instead. + */ + public const PKDataDetectorTypeLink = 'PKDataDetectorTypeLink'; + + /** + * @deprecated please use ::DATA_DETECTOR_TYPE_ADDRESS instead. + */ + public const PKDataDetectorTypeAddress = 'PKDataDetectorTypeAddress'; + + /** + * @deprecated please use ::DATA_DETECTOR_TYPE_CALENDAR_EVENT instead. + */ + public const PKDataDetectorTypeCalendarEvent = 'PKDataDetectorTypeCalendarEvent'; /** * @var string */ - const PKDataDetectorTypePhoneNumber = 'PKDataDetectorTypePhoneNumber'; + public const DATA_DETECTOR_TYPE_PHONE_NUMBER = 'PKDataDetectorTypePhoneNumber'; /** * @var string */ - const PKDataDetectorTypeLink = 'PKDataDetectorTypeLink'; + public const DATA_DETECTOR_TYPE_LINK = 'PKDataDetectorTypeLink'; /** * @var string */ - const PKDataDetectorTypeAddress = 'PKDataDetectorTypeAddress'; + public const DATA_DETECTOR_TYPE_ADDRESS = 'PKDataDetectorTypeAddress'; /** * @var string */ - const PKDataDetectorTypeCalendarEvent = 'PKDataDetectorTypeCalendarEvent'; + public const DATA_DETECTOR_TYPE_CALENDAR_EVENT = 'PKDataDetectorTypeCalendarEvent'; /** * Format string for the alert text that is displayed when the pass is updated. @@ -68,7 +89,7 @@ class Field implements FieldInterface /** * The key must be unique within the scope of the entire pass. * For example, “departure-gate”. - * @var array + * @var string */ protected $key; @@ -118,10 +139,10 @@ public function __construct($key, $value) public function toArray() { - $array = array( + $array = [ 'key' => $this->getKey(), 'value' => $this->getValue() - ); + ]; if ($this->getChangeMessage()) { $array['changeMessage'] = $this->getChangeMessage(); @@ -269,4 +290,4 @@ public function getDataDetectorTypes() { return $this->dataDetectorTypes; } -} \ No newline at end of file +} diff --git a/src/Passbook/Pass/FieldInterface.php b/src/Passbook/Pass/FieldInterface.php index fb58338..474ea5d 100644 --- a/src/Passbook/Pass/FieldInterface.php +++ b/src/Passbook/Pass/FieldInterface.php @@ -23,77 +23,77 @@ interface FieldInterface extends ArrayableInterface /** * Sets change message * - * @param string + * @param string $changeMessage */ public function setChangeMessage($changeMessage); /** * Returns change message * - * @param string + * @return string */ public function getChangeMessage(); /** * Sets key * - * @param string + * @param string $key */ public function setKey($key); /** * Returns key * - * @param string + * @return string */ public function getKey(); /** * Sets label * - * @param string + * @param string $label */ public function setLabel($label); /** * Returns label * - * @param string + * @return string */ public function getLabel(); /** * Sets text alignment * - * @param string + * @param string $textAlignment */ public function setTextAlignment($textAlignment); /** * Returns text alignment * - * @param string + * @return string */ public function getTextAlignment(); /** * Sets value * - * @param string + * @param string $value */ public function setValue($value); /** * Returns value * - * @param string|int|float + * @return string|int|float */ public function getValue(); /** * Sets Attributed Value * - * @param string $attributedValue + * @param string $attributedValue $attributedValue */ public function setAttributedValue($attributedValue); diff --git a/src/Passbook/Pass/ImageInterface.php b/src/Passbook/Pass/ImageInterface.php index 4fb4cf7..df098db 100644 --- a/src/Passbook/Pass/ImageInterface.php +++ b/src/Passbook/Pass/ImageInterface.php @@ -20,25 +20,37 @@ interface ImageInterface { /** * Set image context - * @param boolean + * @param string $context */ public function setContext($context); /** * Get image context - * @param string + * @return string */ public function getContext(); /** * Sets image density - * @param integer + * @param integer $density */ public function setDensity($density); /** * Returns image density - * @param integer + * @return integer */ public function getDensity(); + + /** + * Implemented in \SplFileObject + * @return string + */ + public function getExtension(); + + /** + * Implemented in \SplFileObject + * @return string + */ + public function getPathname(); } diff --git a/src/Passbook/Pass/LocalizationInterface.php b/src/Passbook/Pass/LocalizationInterface.php index c345a83..ce82c65 100644 --- a/src/Passbook/Pass/LocalizationInterface.php +++ b/src/Passbook/Pass/LocalizationInterface.php @@ -19,14 +19,14 @@ interface LocalizationInterface /** * Sets language * - * @param string + * @param string $language */ public function setLanguage($language); /** * Returns language * - * @param string + * @return string */ public function getLanguage(); @@ -75,7 +75,7 @@ public function getStringsFileOutput(); public function addImage(Image $image); /** - * @return Image[] + * @return ImageInterface[] */ public function getImages(); } diff --git a/src/Passbook/Pass/Location.php b/src/Passbook/Pass/Location.php index 72aab2d..e2c7e02 100644 --- a/src/Passbook/Pass/Location.php +++ b/src/Passbook/Pass/Location.php @@ -53,10 +53,10 @@ public function __construct($latitude, $longitude) public function toArray() { - $array = array( + $array = [ 'latitude' => $this->getLatitude(), 'longitude' => $this->getLongitude() - ); + ]; if ($altitude = $this->getAltitude()) { $array['altitude'] = $altitude; diff --git a/src/Passbook/Pass/LocationInterface.php b/src/Passbook/Pass/LocationInterface.php index 181920c..164810f 100644 --- a/src/Passbook/Pass/LocationInterface.php +++ b/src/Passbook/Pass/LocationInterface.php @@ -23,7 +23,7 @@ interface LocationInterface extends ArrayableInterface /** * Sets location altitude * - * @param float + * @param float $altitude */ public function setAltitude($altitude); @@ -37,7 +37,7 @@ public function getAltitude(); /** * Sets location latitude * - * @param float + * @param float $latitude */ public function setLatitude($latitude); @@ -51,7 +51,7 @@ public function getLatitude(); /** * Sets location longitude * - * @param float + * @param float $longitude */ public function setLongitude($longitude); @@ -65,14 +65,14 @@ public function getLongitude(); /** * Sets location relevant text * - * @param float + * @param string $relevantText */ public function setRelevantText($relevantText); /** * Gets location relevant text * - * @return float + * @return string */ public function getRelevantText(); } diff --git a/src/Passbook/Pass/Nfc.php b/src/Passbook/Pass/Nfc.php index 3c0f67f..d957cbe 100644 --- a/src/Passbook/Pass/Nfc.php +++ b/src/Passbook/Pass/Nfc.php @@ -75,4 +75,3 @@ public function getEncryptionPublicKey() return $this->encryptionPublicKey; } } - diff --git a/src/Passbook/Pass/NfcInterface.php b/src/Passbook/Pass/NfcInterface.php index 80b00ab..55a5d4c 100644 --- a/src/Passbook/Pass/NfcInterface.php +++ b/src/Passbook/Pass/NfcInterface.php @@ -19,7 +19,7 @@ interface NfcInterface extends ArrayableInterface /** * Sets NFC message * - * @param string + * @param string $message */ public function setMessage($message); @@ -33,7 +33,7 @@ public function getMessage(); /** * Sets encryption Public Key * - * @param string + * @param string $encryptionPublicKey */ public function setEncryptionPublicKey($encryptionPublicKey); diff --git a/src/Passbook/Pass/NumberField.php b/src/Passbook/Pass/NumberField.php index c7e3bcf..d6f3e81 100644 --- a/src/Passbook/Pass/NumberField.php +++ b/src/Passbook/Pass/NumberField.php @@ -18,23 +18,39 @@ * * @package Passbook\Pass * @author Florian Morello + * @phpcs:disable Generic.NamingConventions.UpperCaseConstantName */ class NumberField extends Field { + /** + * @deprecated please use ::NUMBER_STYLE_DECIMAL instead. + */ + public const PKNumberStyleDecimal = 'PKNumberStyleDecimal'; + + /** + * @deprecated please use ::NUMBER_STYLE_PERCENT instead. + */ + public const PKNumberStylePercent = 'PKNumberStylePercent'; + + /** + * @deprecated please use ::NUMBER_STYLE_SCIENTIFIC instead. + */ + public const PKNumberStyleScientific = 'PKNumberStyleScientific'; + /** * @var string */ - const PKNumberStyleDecimal = 'PKNumberStyleDecimal'; + public const NUMBER_STYLE_DECIMAL = 'PKNumberStyleDecimal'; /** * @var string */ - const PKNumberStylePercent = 'PKNumberStylePercent'; + public const NUMBER_STYLE_PERCENT = 'PKNumberStylePercent'; /** * @var string */ - const PKNumberStyleScientific = 'PKNumberStyleScientific'; + public const NUMBER_STYLE_SCIENTIFIC = 'PKNumberStyleScientific'; /** * ISO 4217 @@ -129,4 +145,4 @@ public function getValue() // Ensure value is int or float; adding 0 will convert type from string return 0 + parent::getValue(); } -} \ No newline at end of file +} diff --git a/src/Passbook/Pass/StructureInterface.php b/src/Passbook/Pass/StructureInterface.php index bc01cab..fc0b8cf 100644 --- a/src/Passbook/Pass/StructureInterface.php +++ b/src/Passbook/Pass/StructureInterface.php @@ -23,7 +23,7 @@ interface StructureInterface extends ArrayableInterface /** * Adds header field * - * @param Field + * @param Field $headerField */ public function addHeaderField(FieldInterface $headerField); @@ -37,7 +37,7 @@ public function getHeaderFields(); /** * Adds primary field * - * @param Field + * @param Field $primaryField */ public function addPrimaryField(FieldInterface $primaryField); @@ -51,7 +51,7 @@ public function getPrimaryFields(); /** * Adds secondary field * - * @param Field + * @param Field $secondaryField */ public function addSecondaryField(FieldInterface $secondaryField); @@ -65,7 +65,7 @@ public function getSecondaryFields(); /** * Adds auxiliary field * - * @param Field + * @param Field $auxiliaryField */ public function addAuxiliaryField(FieldInterface $auxiliaryField); @@ -79,7 +79,7 @@ public function getAuxiliaryFields(); /** * Adds back field * - * @param Field + * @param Field $backField */ public function addBackField(FieldInterface $backField); diff --git a/src/Passbook/PassFactory.php b/src/Passbook/PassFactory.php index f45e323..92c8342 100644 --- a/src/Passbook/PassFactory.php +++ b/src/Passbook/PassFactory.php @@ -95,7 +95,7 @@ class PassFactory * * @var string */ - const PASS_EXTENSION = '.pkpass'; + public const PASS_EXTENSION = '.pkpass'; public function __construct($passTypeIdentifier, $teamIdentifier, $organizationName, $p12File, $p12Pass, $wwdrFile) { @@ -115,7 +115,7 @@ public function __construct($passTypeIdentifier, $teamIdentifier, $organizationN /** * Set outputPath * - * @param string + * @param string $outputPath * * @return $this */ @@ -149,7 +149,7 @@ public function getNormalizedOutputPath() /** * Set overwrite * - * @param boolean + * @param boolean $overwrite * * @return $this */ @@ -176,7 +176,7 @@ public function isOverwrite() * When set, the pass will not be signed when packaged. This should only * be used for testing. * - * @param boolean + * @param boolean $skipSignature * * @return $this */ @@ -251,7 +251,7 @@ public function package(PassInterface $pass, $passName = '') $this->populateRequiredInformation($pass); if ($this->passValidator) { - if (!$this->passValidator->validate($pass)){ + if (!$this->passValidator->validate($pass)) { throw new PassInvalidException('Failed to validate passbook', $this->passValidator->getErrors()); }; } @@ -304,7 +304,7 @@ private function sign($passDir, $manifestJSONFile): void $signatureFile, $certdata, $privkey, - array(), + [], PKCS7_BINARY | PKCS7_DETACHED, $this->wwdr->getRealPath() ); @@ -326,7 +326,7 @@ private function sign($passDir, $manifestJSONFile): void throw new FileException("Couldn't write signature file."); } } else { - throw new FileException("Error reading certificate file"); + throw new FileException('Error reading certificate file'); } } @@ -342,12 +342,12 @@ private function sign($passDir, $manifestJSONFile): void private function zip($source, $destination) { if (!extension_loaded('zip')) { - throw new Exception("ZIP extension not available"); + throw new Exception('ZIP extension not available'); } $source = realpath($source); if (!is_dir($source)) { - throw new FileException("Source must be a directory."); + throw new FileException('Source must be a directory.'); } $zip = new ZipArchive(); @@ -362,7 +362,7 @@ private function zip($source, $destination) while ($iterator->valid()) { if ($iterator->isDir()) { $zip->addEmptyDir($iterator->getSubPathName()); - } else if ($iterator->isFile()) { + } elseif ($iterator->isFile()) { $zip->addFromString($iterator->getSubPathName(), file_get_contents($iterator->key())); } $iterator->next(); @@ -380,7 +380,7 @@ private function zip($source, $destination) */ private function rrmdir($dir) { - $files = array_diff(scandir($dir), array('.', '..')); + $files = array_diff(scandir($dir), ['.', '..']); foreach ($files as $file) { is_dir("$dir/$file") ? $this->rrmdir("$dir/$file") : unlink("$dir/$file"); } @@ -426,7 +426,7 @@ private static function jsonEncode($array) */ public function getPassName($passName, PassInterface $pass) { - $passNameSanitised = preg_replace("/[^a-zA-Z0-9]+/", "", $passName); + $passNameSanitised = preg_replace('/[^a-zA-Z0-9]+/', '', $passName); return strlen($passNameSanitised) != 0 ? $passNameSanitised : $pass->getSerialNumber(); } @@ -445,7 +445,7 @@ private function prepareManifest($passDir) ); foreach ($files as $file) { // Ignore "." and ".." folders - if (in_array(substr($file, strrpos($file, '/') + 1), array('.', '..'))) { + if (in_array(substr($file, strrpos($file, '/') + 1), ['.', '..'])) { continue; } // @@ -470,7 +470,7 @@ private function preparePassDirectory(PassInterface $pass) $passDir = $this->getNormalizedOutputPath() . $pass->getSerialNumber() . DIRECTORY_SEPARATOR; $passDirExists = file_exists($passDir); if ($passDirExists && !$this->isOverwrite()) { - throw new FileException("Temporary pass directory already exists"); + throw new FileException('Temporary pass directory already exists'); } elseif (!$passDirExists && !mkdir($passDir, 0777, true)) { throw new FileException("Couldn't create temporary pass directory"); } @@ -489,7 +489,7 @@ private function prepareImages(PassInterface $pass, $passDir): void $fileName = $passDir . $image->getContext(); if ($image->getDensity() === 2) { $fileName .= '@2x'; - } else if ($image->getDensity() === 3) { + } elseif ($image->getDensity() === 3) { $fileName .= '@3x'; } @@ -523,7 +523,7 @@ private function prepareLocalizations(PassInterface $pass, $passDir): void $fileName = $localizationDir . $image->getContext(); if ($image->getDensity() === 2) { $fileName .= '@2x'; - } else if ($image->getDensity() === 3) { + } elseif ($image->getDensity() === 3) { $fileName .= '@3x'; } $fileName .= '.' . $image->getExtension(); diff --git a/src/Passbook/PassInterface.php b/src/Passbook/PassInterface.php index 28e7904..ae3623a 100644 --- a/src/Passbook/PassInterface.php +++ b/src/Passbook/PassInterface.php @@ -86,7 +86,7 @@ public function getStructure(); public function addImage(ImageInterface $image); /** - * @return Image[] + * @return ImageInterface[] */ public function getImages(); @@ -119,17 +119,16 @@ public function addBeacon(BeaconInterface $beacon); * {@inheritdoc} */ public function getBeacons(); - + /** * {@inheritdoc} */ public function addNfc(NfcInterface $nfc); /** - * {@inheritdoc} + * @return NfcInterface[] */ public function getNfc(); - /** * {@inheritdoc} @@ -228,7 +227,7 @@ public function setLogoText($logoText); * {@inheritdoc} */ public function getLogoText(); - + /** * {@inheritdoc} */ @@ -237,7 +236,7 @@ public function setSharingProhibited(bool $sharingProhibited); /** * {@inheritdoc} */ - public function getSharingProhibited(); + public function getSharingProhibited(); /** * {@inheritdoc} @@ -310,25 +309,24 @@ public function addLocalization(LocalizationInterface $localization); * @return LocalizationInterface[] */ public function getLocalizations(); - + /** * {@inheritdoc} */ public function setAppLaunchURL($appLaunchURL); - + /** * {@inheritdoc} */ public function getAppLaunchURL(); - /** - * {@inheritdoc} - */ - public function setUserInfo($userInfo); - - /** - * {@inheritdoc} - */ - public function getUserInfo(); + /** + * {@inheritdoc} + */ + public function setUserInfo($userInfo); + /** + * {@inheritdoc} + */ + public function getUserInfo(); } diff --git a/src/Passbook/PassValidator.php b/src/Passbook/PassValidator.php index 74418ee..577480c 100644 --- a/src/Passbook/PassValidator.php +++ b/src/Passbook/PassValidator.php @@ -21,32 +21,32 @@ class PassValidator implements PassValidatorInterface { private $errors; - const DESCRIPTION_REQUIRED = 'description is required and cannot be blank'; - const FORMAT_VERSION_REQUIRED = 'formatVersion is required and must be 1'; - const ORGANIZATION_NAME_REQUIRED = 'organizationName is required and cannot be blank'; - const PASS_TYPE_IDENTIFIER_REQUIRED = 'passTypeIdentifier is required and cannot be blank'; - const SERIAL_NUMBER_REQUIRED = 'serialNumber is required and cannot be blank'; - const TEAM_IDENTIFIER_REQUIRED = 'teamIdentifier is required and cannot be blank'; - const ICON_REQUIRED = 'pass must have an icon image'; - const BARCODE_FORMAT_INVALID = 'barcode format is invalid'; - const BARCODE_MESSAGE_INVALID = 'barcode message is invalid; must be a string'; - const LOCATION_LATITUDE_REQUIRED = 'location latitude is required'; - const LOCATION_LONGITUDE_REQUIRED = 'location longitude is required'; - const LOCATION_LATITUDE_INVALID = 'location latitude is invalid; must be numeric'; - const LOCATION_LONGITUDE_INVALID = 'location longitude is invalid; must be numeric'; - const LOCATION_ALTITUDE_INVALID = 'location altitude is invalid; must be numeric'; - const BEACON_PROXIMITY_UUID_REQUIRED = 'beacon proximityUUID is required'; - const BEACON_MAJOR_INVALID = 'beacon major is invalid; must be 16-bit unsigned integer'; - const BEACON_MINOR_INVALID = 'beacon minor is invalid; must be 16-bit unsigned integer'; - const NFC_MESSAGE_REQUIRED = 'NFC message is required'; - const NFC_ENCRYPTION_PUBLIC_KEY_REQUIRED = 'NFC encryption public key is required'; - const WEB_SERVICE_URL_INVALID = 'webServiceURL is invalid; must start with https (or http for development)'; - const WEB_SERVICE_AUTHENTICATION_TOKEN_REQUIRED = 'authenticationToken required with webServiceURL and cannot be blank'; - const WEB_SERVICE_AUTHENTICATION_TOKEN_INVALID = 'authenticationToken is invalid; must be at least 16 characters'; - const ASSOCIATED_STORE_IDENTIFIER_INVALID = 'associatedStoreIdentifiers is invalid; must be an integer'; - const ASSOCIATED_STORE_IDENTIFIER_REQUIRED = 'appLaunchURL is required when associatedStoreIdentifiers is present'; - const IMAGE_TYPE_INVALID = 'image files must be PNG format'; - const GROUPING_IDENTITY_INVALID = 'the grouping identity may only be used on boarding pass and event ticket types'; + public const DESCRIPTION_REQUIRED = 'description is required and cannot be blank'; + public const FORMAT_VERSION_REQUIRED = 'formatVersion is required and must be 1'; + public const ORGANIZATION_NAME_REQUIRED = 'organizationName is required and cannot be blank'; + public const PASS_TYPE_IDENTIFIER_REQUIRED = 'passTypeIdentifier is required and cannot be blank'; + public const SERIAL_NUMBER_REQUIRED = 'serialNumber is required and cannot be blank'; + public const TEAM_IDENTIFIER_REQUIRED = 'teamIdentifier is required and cannot be blank'; + public const ICON_REQUIRED = 'pass must have an icon image'; + public const BARCODE_FORMAT_INVALID = 'barcode format is invalid'; + public const BARCODE_MESSAGE_INVALID = 'barcode message is invalid; must be a string'; + public const LOCATION_LATITUDE_REQUIRED = 'location latitude is required'; + public const LOCATION_LONGITUDE_REQUIRED = 'location longitude is required'; + public const LOCATION_LATITUDE_INVALID = 'location latitude is invalid; must be numeric'; + public const LOCATION_LONGITUDE_INVALID = 'location longitude is invalid; must be numeric'; + public const LOCATION_ALTITUDE_INVALID = 'location altitude is invalid; must be numeric'; + public const BEACON_PROXIMITY_UUID_REQUIRED = 'beacon proximityUUID is required'; + public const BEACON_MAJOR_INVALID = 'beacon major is invalid; must be 16-bit unsigned integer'; + public const BEACON_MINOR_INVALID = 'beacon minor is invalid; must be 16-bit unsigned integer'; + public const NFC_MESSAGE_REQUIRED = 'NFC message is required'; + public const NFC_ENCRYPTION_PUBLIC_KEY_REQUIRED = 'NFC encryption public key is required'; + public const WEB_SERVICE_URL_INVALID = 'webServiceURL is invalid; must start with https (or http for development)'; + public const WEB_SERVICE_AUTHENTICATION_TOKEN_REQUIRED = 'authenticationToken required with webServiceURL and cannot be blank'; + public const WEB_SERVICE_AUTHENTICATION_TOKEN_INVALID = 'authenticationToken is invalid; must be at least 16 characters'; + public const ASSOCIATED_STORE_IDENTIFIER_INVALID = 'associatedStoreIdentifiers is invalid; must be an integer'; + public const ASSOCIATED_STORE_IDENTIFIER_REQUIRED = 'appLaunchURL is required when associatedStoreIdentifiers is present'; + public const IMAGE_TYPE_INVALID = 'image files must be PNG format'; + public const GROUPING_IDENTITY_INVALID = 'the grouping identity may only be used on boarding pass and event ticket types'; /** * {@inheritdoc} @@ -185,7 +185,7 @@ private function validateLocation(Location $location) private function validateBarcodeKeys(PassInterface $pass) { - $validBarcodeFormats = array(Barcode::TYPE_QR, Barcode::TYPE_AZTEC, Barcode::TYPE_PDF_417, Barcode::TYPE_CODE_128); + $validBarcodeFormats = [Barcode::TYPE_QR, Barcode::TYPE_AZTEC, Barcode::TYPE_PDF_417, Barcode::TYPE_CODE_128]; $barcode = $pass->getBarcode(); @@ -279,5 +279,4 @@ private function addError($string) { $this->errors[] = $string; } - } diff --git a/src/Passbook/PassValidatorInterface.php b/src/Passbook/PassValidatorInterface.php index 24e3789..466c6a6 100644 --- a/src/Passbook/PassValidatorInterface.php +++ b/src/Passbook/PassValidatorInterface.php @@ -20,5 +20,4 @@ public function validate(PassInterface $pass); * @return string[] */ public function getErrors(); - } diff --git a/src/Passbook/Type/BoardingPass.php b/src/Passbook/Type/BoardingPass.php index 3cc300c..2b44872 100644 --- a/src/Passbook/Type/BoardingPass.php +++ b/src/Passbook/Type/BoardingPass.php @@ -43,27 +43,27 @@ class BoardingPass extends Pass /** * @var string */ - const TYPE_AIR = 'PKTransitTypeAir'; + public const TYPE_AIR = 'PKTransitTypeAir'; /** * @var string */ - const TYPE_BOAT = 'PKTransitTypeBoat'; + public const TYPE_BOAT = 'PKTransitTypeBoat'; /** * @var string */ - const TYPE_BUS = 'PKTransitTypeBus'; + public const TYPE_BUS = 'PKTransitTypeBus'; /** * @var string */ - const TYPE_GENERIC = 'PKTransitTypeGeneric'; + public const TYPE_GENERIC = 'PKTransitTypeGeneric'; /** * @var string */ - const TYPE_TRAIN = 'PKTransitTypeTrain'; + public const TYPE_TRAIN = 'PKTransitTypeTrain'; /** * Class constructor diff --git a/tests/Passbook/Tests/Certificate/P12Test.php b/tests/Passbook/Tests/Certificate/P12Test.php index 540d37e..1ca4413 100644 --- a/tests/Passbook/Tests/Certificate/P12Test.php +++ b/tests/Passbook/Tests/Certificate/P12Test.php @@ -10,7 +10,7 @@ class P12Test extends TestCase { public function testP12() { - $p12 = new P12(__DIR__.'/../../../cert/pass.com.example.testpass.p12', '123456'); + $p12 = new P12(__DIR__ . '/../../../cert/pass.com.example.testpass.p12', '123456'); $this->assertEquals($p12->getPassword(), '123456'); } @@ -18,6 +18,6 @@ public function testP12() public function testP12Exception() { $this->expectException(FileNotFoundException::class); - new P12(__DIR__.'/non-existing-file', '123456'); + new P12(__DIR__ . '/non-existing-file', '123456'); } -} \ No newline at end of file +} diff --git a/tests/Passbook/Tests/Certificate/WWDRTest.php b/tests/Passbook/Tests/Certificate/WWDRTest.php index 2c867b9..7303dc5 100644 --- a/tests/Passbook/Tests/Certificate/WWDRTest.php +++ b/tests/Passbook/Tests/Certificate/WWDRTest.php @@ -10,13 +10,13 @@ class WWDRTest extends TestCase { public function testWWDR() { - $wwdr = new WWDR(__DIR__.'/../../../cert/wwdr.pem'); + $wwdr = new WWDR(__DIR__ . '/../../../cert/wwdr.pem'); $this->assertInstanceOf(WWDR::class, $wwdr); } public function testWWDRException() { $this->expectException(FileNotFoundException::class); - new WWDR(__DIR__.'/non-existing-file'); + new WWDR(__DIR__ . '/non-existing-file'); } -} \ No newline at end of file +} diff --git a/tests/Passbook/Tests/Exception/PassInvalidExceptionTest.php b/tests/Passbook/Tests/Exception/PassInvalidExceptionTest.php index aa9f577..fe54359 100644 --- a/tests/Passbook/Tests/Exception/PassInvalidExceptionTest.php +++ b/tests/Passbook/Tests/Exception/PassInvalidExceptionTest.php @@ -17,7 +17,7 @@ public function testNewExceptionWithoutErrorsArray() public function testNewExceptionWithErrorsArray() { - $errors = array('error 1', 'error 2'); + $errors = ['error 1', 'error 2']; $exception = new PassInvalidException('', $errors); self::assertTrue(is_array($exception->getErrors())); @@ -26,12 +26,11 @@ public function testNewExceptionWithErrorsArray() public function testNewExceptionWithMessageAndArray() { - $errors = array('error 1', 'error 2'); + $errors = ['error 1', 'error 2']; $exception = new PassInvalidException('Exception message', $errors); self::assertTrue(is_array($exception->getErrors())); self::assertEquals($errors, $exception->getErrors()); self::assertSame('Exception message', $exception->getMessage()); } - } diff --git a/tests/Passbook/Tests/Pass/BarcodeTest.php b/tests/Passbook/Tests/Pass/BarcodeTest.php index b4ef962..5da4609 100644 --- a/tests/Passbook/Tests/Pass/BarcodeTest.php +++ b/tests/Passbook/Tests/Pass/BarcodeTest.php @@ -42,4 +42,4 @@ public function testBarcodeMessageIsString() $barcode->setMessage(null); $this->assertEquals('', $barcode->getMessage()); } -} \ No newline at end of file +} diff --git a/tests/Passbook/Tests/Pass/BeaconTest.php b/tests/Passbook/Tests/Pass/BeaconTest.php index 070ebce..6be5c6e 100644 --- a/tests/Passbook/Tests/Pass/BeaconTest.php +++ b/tests/Passbook/Tests/Pass/BeaconTest.php @@ -29,4 +29,4 @@ public function testBeacon() $this->assertEquals($expected, $beacon->toArray()); } -} \ No newline at end of file +} diff --git a/tests/Passbook/Tests/Pass/FieldTest.php b/tests/Passbook/Tests/Pass/FieldTest.php index d068369..695c1b3 100644 --- a/tests/Passbook/Tests/Pass/FieldTest.php +++ b/tests/Passbook/Tests/Pass/FieldTest.php @@ -10,17 +10,17 @@ class FieldTest extends TestCase { - public function testField() - { - $field = new Field('key', 'val'); - $field - ->setChangeMessage('change-message') - ->setTextAlignment(Field::ALIGN_RIGHT) - ; - - $array = $field->toArray(); - $this->assertArrayHasKey('key', $array); - } + public function testField() + { + $field = new Field('key', 'val'); + $field + ->setChangeMessage('change-message') + ->setTextAlignment(Field::ALIGN_RIGHT) + ; + + $array = $field->toArray(); + $this->assertArrayHasKey('key', $array); + } public function testDateField() { @@ -31,14 +31,14 @@ public function testDateField() $this->assertEquals('2014-01-01T00:00:00+00:00', $array['value']); } - public function testNumberField() - { - $field = new NumberField('key', 0); - $field - ->setNumberStyle(NumberField::PKNumberStyleDecimal) - ->setCurrencyCode('EUR') - ; - - $this->assertArrayHasKey('currencyCode', $field->toArray()); - } -} \ No newline at end of file + public function testNumberField() + { + $field = new NumberField('key', 0); + $field + ->setNumberStyle(NumberField::NUMBER_STYLE_DECIMAL) + ->setCurrencyCode('EUR') + ; + + $this->assertArrayHasKey('currencyCode', $field->toArray()); + } +} diff --git a/tests/Passbook/Tests/Pass/ImageTest.php b/tests/Passbook/Tests/Pass/ImageTest.php index 4e57a9d..53531e4 100644 --- a/tests/Passbook/Tests/Pass/ImageTest.php +++ b/tests/Passbook/Tests/Pass/ImageTest.php @@ -9,7 +9,7 @@ class ImageTest extends TestCase { public function testImage() { - $image = new Image(__DIR__.'/../../../img/icon.png', 'thumbnail'); + $image = new Image(__DIR__ . '/../../../img/icon.png', 'thumbnail'); $image->setDensity(2); $this->assertEquals($image->getContext(), 'thumbnail'); @@ -18,7 +18,7 @@ public function testImage() public function testImage3x() { - $image = new Image(__DIR__.'/../../../img/icon.png', 'thumbnail'); + $image = new Image(__DIR__ . '/../../../img/icon.png', 'thumbnail'); $image->setDensity(3); $this->assertEquals('thumbnail', $image->getContext()); diff --git a/tests/Passbook/Tests/Pass/LocationTest.php b/tests/Passbook/Tests/Pass/LocationTest.php index 937cec4..6befbef 100644 --- a/tests/Passbook/Tests/Pass/LocationTest.php +++ b/tests/Passbook/Tests/Pass/LocationTest.php @@ -28,4 +28,4 @@ public function testBarcode() $this->assertEquals($expected, $location->toArray()); } -} \ No newline at end of file +} diff --git a/tests/Passbook/Tests/Pass/NumberFieldTest.php b/tests/Passbook/Tests/Pass/NumberFieldTest.php index 12efe80..9384546 100644 --- a/tests/Passbook/Tests/Pass/NumberFieldTest.php +++ b/tests/Passbook/Tests/Pass/NumberFieldTest.php @@ -2,7 +2,6 @@ namespace Passbook\Tests\Pass; - use Passbook\Pass\NumberField; use PHPUnit\Framework\TestCase; @@ -16,5 +15,4 @@ public function testValueIsNumber() $field = new NumberField('price', '12'); $this->assertIsInt($field->getValue()); } - } diff --git a/tests/Passbook/Tests/Pass/StructureTest.php b/tests/Passbook/Tests/Pass/StructureTest.php index 9d6822a..c400cea 100644 --- a/tests/Passbook/Tests/Pass/StructureTest.php +++ b/tests/Passbook/Tests/Pass/StructureTest.php @@ -17,14 +17,14 @@ public function testStructure() $actual = $structure->toArray(); $expected = [ - "headerFields" => [ - ["key" => "balance", "value" => "13.50 USD"], + 'headerFields' => [ + ['key' => 'balance', 'value' => '13.50 USD'], ], - "backFields" => [ - ["key" => "publisher", "value" => "Passbook Limited"] + 'backFields' => [ + ['key' => 'publisher', 'value' => 'Passbook Limited'] ] ]; $this->assertEquals($expected, $actual); } -} \ No newline at end of file +} diff --git a/tests/Passbook/Tests/PassFactoryTest.php b/tests/Passbook/Tests/PassFactoryTest.php index f85f34a..f0e66db 100644 --- a/tests/Passbook/Tests/PassFactoryTest.php +++ b/tests/Passbook/Tests/PassFactoryTest.php @@ -108,13 +108,13 @@ public function testFactoryPackage() $pass->setBarcode($barcode); // Add Localizations (this also tests zipping subdirectories) - $englishText = array( + $englishText = [ 'created_by' => 'Pass produced by php-passbook' - ); + ]; - $spanishText = array( + $spanishText = [ 'created_by' => 'Pase producido por php-passbook' - ); + ]; $es = new Localization('es'); $es->addStrings($spanishText); @@ -188,7 +188,7 @@ public function testNormalizedOutputPath() $this->factory->setOutputPath("path-ending-with-separator{$s}"); self::assertEquals("path-ending-with-separator{$s}", $this->factory->getNormalizedOutputPath()); - $this->factory->setOutputPath("path-not-ending-with-separator"); + $this->factory->setOutputPath('path-not-ending-with-separator'); self::assertEquals("path-not-ending-with-separator{$s}", $this->factory->getNormalizedOutputPath()); $this->factory->setOutputPath("path-ending-with-multiple-separators{$s}{$s}"); diff --git a/tests/Passbook/Tests/PassTest.php b/tests/Passbook/Tests/PassTest.php index 4c7d5ca..38a4e5d 100644 --- a/tests/Passbook/Tests/PassTest.php +++ b/tests/Passbook/Tests/PassTest.php @@ -260,7 +260,7 @@ public function testPass() ->addAssociatedStoreIdentifier(123) ; - $properties = array( + $properties = [ 'webServiceURL', 'foregroundColor', 'backgroundColor', @@ -270,7 +270,7 @@ public function testPass() 'suppressStripShine', 'associatedStoreIdentifiers', 'appLaunchURL', - ); + ]; $array = $this->pass->toArray(); foreach ($properties as $property) { $this->assertTrue(isset($array[$property])); diff --git a/tests/Passbook/Tests/PassValidatorTest.php b/tests/Passbook/Tests/PassValidatorTest.php index d6fb95e..a9a695f 100644 --- a/tests/Passbook/Tests/PassValidatorTest.php +++ b/tests/Passbook/Tests/PassValidatorTest.php @@ -13,8 +13,8 @@ class PassValidatorTest extends TestCase { - const SERIAL_NUMBER = '123'; - const DESCRIPTION = 'description'; + protected const SERIAL_NUMBER = '123'; + protected const DESCRIPTION = 'description'; /** * @var Pass @@ -114,7 +114,7 @@ public function testPassLocation() $this->assertPasses($this->pass, PassValidator::LOCATION_LATITUDE_REQUIRED); $this->assertPasses($this->pass, PassValidator::LOCATION_ALTITUDE_INVALID); - $location = new Location(0,0); + $location = new Location(0, 0); $this->pass->addLocation($location); $this->assertPasses($this->pass, PassValidator::LOCATION_LONGITUDE_REQUIRED); $this->assertPasses($this->pass, PassValidator::LOCATION_LATITUDE_REQUIRED); @@ -197,7 +197,7 @@ public function testPassWithoutIcon() self::assertArrayNotHasKey('icon', $this->pass->getImages(), 'pass must not have an icon for test to be valid'); $this->assertFails($this->pass, PassValidator::ICON_REQUIRED); - $icon = new Image(__DIR__.'/../../img/icon.png', 'icon'); + $icon = new Image(__DIR__ . '/../../img/icon.png', 'icon'); $this->pass->addImage($icon); $this->assertPasses($this->pass, PassValidator::ICON_REQUIRED); } diff --git a/tests/cert/pass.com.example.testpass.p12 b/tests/cert/pass.com.example.testpass.p12 index 2e15a13..6eb08fe 100644 Binary files a/tests/cert/pass.com.example.testpass.p12 and b/tests/cert/pass.com.example.testpass.p12 differ diff --git a/www/router.php b/www/router.php index 1c18f9a..45dbbd9 100644 --- a/www/router.php +++ b/www/router.php @@ -1,12 +1,12 @@ "; - echo ''.$pass.''; - echo "".round(filesize($dir.$pass) / 1024)."KB"; - echo "".date('Y-m-d H:i:s', filectime($dir.$pass)).""; - echo ""; + echo ''; + echo '' . $pass . ''; + echo '' . round(filesize($dir . $pass) / 1024) . 'KB'; + echo '' . date('Y-m-d H:i:s', filectime($dir . $pass)) . ''; + echo ''; } ?>