From b3fa99b1356881c3d108316f1e5f59625977df5a Mon Sep 17 00:00:00 2001 From: Razvan Grigore Date: Wed, 10 Jan 2024 13:31:17 +0200 Subject: [PATCH 1/9] Add github actions, fix phpunit tests Also repacked the test p12 cert so it works with openssl3 in PHP 8.2, see https://www.php.net/manual/en/function.openssl-pkcs12-read.php#128992 --- .circleci/config.yml | 32 ----- .github/workflows/test.yml | 36 ++++++ .scrutinizer.yml | 151 ----------------------- .travis.yml | 14 --- composer.json | 5 + phpunit.xml.dist | 29 +++-- tests/cert/pass.com.example.testpass.p12 | Bin 2773 -> 2915 bytes 7 files changed, 55 insertions(+), 212 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 .github/workflows/test.yml delete mode 100644 .scrutinizer.yml delete mode 100644 .travis.yml 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/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..49a6fbc --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,36 @@ +name: PHPUnit + +on: [push, pull_request] + +jobs: + run: + runs-on: ubuntu-latest + strategy: + matrix: + php-version: ['7.4', '8.0', '8.1', '8.2'] + name: PHPUnit w/ 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: 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/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index 67fcf60..0000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,151 +0,0 @@ -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: { } 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/composer.json b/composer.json index 63649e9..01b88ff 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,11 @@ "email": "eymen@egunay.com" } ], + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } + }, "require": { "php": ">=7.4", "ext-zip": "*", 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/tests/cert/pass.com.example.testpass.p12 b/tests/cert/pass.com.example.testpass.p12 index 2e15a13f79ff66d5069b46e6cd783b04ac97961b..6eb08fe297f3270f1b3f672532b06f3ec3043f63 100644 GIT binary patch literal 2915 zcmai$X*3iJ7st&Q+gL_f$5zI^kFiH~5jDICm9d8r29aGD3?fU`LYAa3_AS}>2=R<9 zGKjI1%#avGUe9^o)ARB9aL+ye|Nq>3zx~dIW0@U*09rVfnTwuD8fSt#WCbt)im=S| zAS^Qwjs^dQW9jby6VVr8>0HjNvmu(ZcI%%60Jr%g=vd*VaH)SJ3tRxiSl1^o^0DND zBoN3*181RU{NFVo6CDj)ke{1oJOa0!X`)$>z`4BInOB5DFSr7*4vAG8^YBk!C(pzs=-*s=>V7jxQ zUq$3XGEq~EM|VaLypx8I-t`*>NY6dr6jBmhZC+fyXo_tM%3&p%@C&5^Do2(tq;2SM zbQf7$&Ef@Ywxi#*mFT|Gu3#@vIzp=GE)~PetA__v z5o6R^O&VbhDy9n-)r<(s2yVqQYfRC2|TZ zu02fSvTgmdHud&M*fc_T=53JVtI*x|d#iq*$D|bMxnI;FT5}VJQo0)paXjWlAgQDg3>E+K0;Ixjz z>13*uoY&_PRhm)1XyzZZx( zO-kI82|NV)KkwkwGqdPpfa;@Fk=gmlK_Vk3CfJS;iU`wI%EjL&tsSiPrXue8Y{Nc} zU6af%O)0N>Y7N;_oVB8_5BO}GmD}Yf6L}5JpXhQl5LQ^_ouzHym=Of^ypSynn(Dly zr?a17N;fJQP|aK;{UTaKQBJbm0G@)n7@u{*%*i`b{*%&Se6P4|)xTOeFH-Vm@OGh@ zs_NJNS<~<+z8UIzKGlS?4nkIc>N9`z`gTOI7gQ~gU60xHm(3;G0M)kEv)$p${4SqP zvtqnIJ{lGMjwRWS>I|}sl`Pfrg-$1Q+C`T?cS?}=Z++U-t(LuJbj@&1xT?kv@++68 z_I8}8JhJC>98FuJwn^6#)0NkGO+!J=OuQff?T9)y_8;);dQM@@x4Z+Rv^~y? zy3cBr{$se%VcJ@sXtkMgGUG42#&tKk;(T>fsa+0@HU);Z=GNux`v8@MJ$hI-tKkpK zUXDkxbJG0mnK_`KUZX!o+|+D1JWP6QvL|Ia{quo$pbb*?=m?auPl}is*LI|x=KO_8 zX22`IFY-0Hr-hi{ZwgHRHt~qAH*Vz-WD#n_Hoi~iZsrqpMHbvPdo?~aeu6>nST>jr zb`JSvqS13j24B>P_Xzj8P^k;L{gd~nhsFr-j*4RJ%{2R!04?tKtzcbtWtUTzM|Ica`FaUTKDxR5g{{~Ro1X z+UKTQFn<3Z5B*;YABS+TglssFFrz2p8)TU$Q=~gE6v6hx2$>ASI|BPpA|^+-gs!qx zUaz-5Or}g0H4h}@c#8(h`>tB$)@c!rJy|WHcm}JpM<|yzr7^+ya+HCXx)x?0+T6u1 zHrHpnh{WF@I7fB>lVvvPI<|1Py^1Zw-4p;`s+*GgI|V!Zjdigb6sNGxwiTpm5BW>l zGn%HY_jgSo+>i_{fZ5NTA9k921b2aW*<~JM65&GLLcvGf%RX|W6&Zulp-MdQO$ppR zwLbyC&0NnFm6s=t+NC&ViA+P5>YEC1!q|i1A@L!R6R&0Q@xv6?yUVqrH-4*emhz;% zEiS()oi&w}ha0)&jFQXpAAXJ;S zz_lq_w062cbRJV1$l%k*n}2bh$nXyGf~ISBcxQZ*e%lv3utT$xhmZ5G z(9}b#cF)ytByn%RRzy_8T%t~U7_0*IN1HA(ybk1dXrJia&RxpzMzjpF3nZ5E+MW_n z7ogKgHGF9;GIA}K^POPg*#V88TC(>NEK>q&_iH-A(eirLaWCR5`b)nXo}bLnbvS2B z0_N4WO2xh`pb^6lbE7%bc6DX{Lu%A~L0oBQEU`|sOA}mwdy3fjbeMg^Yr(#sU4#J1 ztOSo)1~Ae;=`CP}Mu8U6VC!Gmlm<2r~ADy&KEG4=OL8opze-*EH{E~(;t%Uqij&BeZ-PsSBWd9oi*DTh71 zF%Zt{4qEzcz$@o32`0W@K!#5;!d-rpDE~#IJ*`r48aXI0ZgTyK&cGsqz1?5Nz}Pro z#7D7(-nNQjaFIWNW#Urg25}yZVxqPaBMI7=JqNtC?QY}Gg>ASVToKOt=RE}i=x9I} x@pht3p7*$-vN)fC_(e{0bgM}e2wa{AjYO@uyg`jfZ^Y${V#DPRbc=C delta 2764 zcmV;-3N!WN7S$DhFoFuv0s#Xsf(n-g2`Yw2hW8Bt2LYgh3Wx-P3WP9%3V<+z1vdr> zDuzgg_YDCD2B3lkC@_KrBmw~dFoFdg1_>&LNQU>tqUapx4nMw{4V84{1qD2Bz%r~+PEL2?}?;7$#AK2$uU;tDvPxv z&iPn7y$J^f;+_jJBX6Vp?sYGqg?CgBB(BdkagkPh7{h<96-`h|h|ww|sJhgE(l{Mq z`m?2fPw~cT;9e{@0x#|97fYBUVEFo_eib$CU(ay*8BU$(kEDI=JqAlR1kT?{l@yqe z#l6L&*XTZxd5m~7quGeu>BBvtnwJgIPCBz{XVHZA{4E*6;}cYr#uTP#^D2Fg0w4@k z4^U}DwIeNm8_f~&A)1iT!vY5&vEV0Od=Zt^JM(=t zB1OH1d)f^`D9x>mbNK7lgi3eb>DTja2Z#8)+NPHTaB`>!DDC>01q7`BGf<@#RVm$rHpw5G#v;PbO|DTUwXmdK zrDYqDzR*Jy9Iy|-H{6B_4Y_J^2;2Kjy+1pbe8IA3&7j56fzy#Zw`zKttEuz^x`j6h z5(?{&q8TkBdwrF%9_}G18Qy}Qd1dE6gVtP!<-BXBBz)t+54 zryHbCSL}j{O=bN&HP&{i!}R3B?Qr^E(V5iu`?I<4(F)qOm)GqE_Ky% z19PV+23F8?1PRnY=|}-(*~r$MuZA*{rtVfznCe}Bqh8_t97r&t-9-ed z5%JmM9d9-LE8YvC54*Wz_7*1zP{=>2W5$(0iak?pqgqGjVy-Cfgf+;#TMy> zQe8(i8Kw7ND%}c=RZk1w9!PG!E-W+ynmZ)$4S4vx3YR0S8!rIWHyUzG3&Y=x_kD7N z3I0@;fFPr1Cv{DKl9c0yVIMg}Ps&4C6&*d+COVPN_Lj{9w$(g&T8GU3lo2uIgS(E- zA}0wK9)o5UrH1L`84jX(U1lO=6wZZyqjUJOGJ{`%%yuCBF@97uN_2KMa23cmGBi#Z+#wiVoNiBNb!Fxj5(>rp)V z1t*em!zIj5aI=LM-r#~O2-yK(@lpLxl}hJ6`-L?zv+aJL9`l3rF8k-M@oCvtCNon^ zZMw)fzNS*6=P{ah2re;%?cZ9j9PA1ef^3>C zOjkFK$;T+_aEy-;5n#Y$PwCc0C1$66dkka`b9pdIOi0fK2o`S$X1!jjJ_v0dfuF(K zYLJ)6%=-}>EJR=MdR2)7wrIeQz@&AE?7CN{%>SpGn0yQ~?1luvFhD$fQ1$w)^}%uTvw7`hW@UuBXTsN|FOB^CGe8iqQ&61rRLN)?$7!l%t>$~{ zP)dPoyh8c7c;>HnI+LT`n@?PLf!n)(tXq?1ZnYr7-%ND?uW(NH5s7u4<3mfF~ntxXtaHDS~YlrXnXNcBjd73(g$(H1?+ub)>ZL zFMlKan7U1$9nkRjllclLGBGeAFbM_)D-Ht!8U+9Z6d*=mDZjSG_@8)1qpX`UL Date: Wed, 10 Jan 2024 13:54:52 +0200 Subject: [PATCH 2/9] Rename actions name and trigger only once per MR --- .github/workflows/test.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 49a6fbc..a1c32ce 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,13 @@ name: PHPUnit -on: [push, pull_request] +on: + push: + branches: + - master + paths-ignore: + - README.md + pull_request: + workflow_dispatch: jobs: run: @@ -8,7 +15,7 @@ jobs: strategy: matrix: php-version: ['7.4', '8.0', '8.1', '8.2'] - name: PHPUnit w/ PHP ${{ matrix.php-version }} + name: PHP ${{ matrix.php-version }} steps: - uses: actions/checkout@v4 From b6a05d7373db467e9a1de95dac88bdd470eaf911 Mon Sep 17 00:00:00 2001 From: Razvan Grigore Date: Wed, 10 Jan 2024 21:41:55 +0200 Subject: [PATCH 3/9] Add scrutinizer back for code coverage badge --- .scrutinizer.yml | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .scrutinizer.yml diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 0000000..effa195 --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,38 @@ +checks: + php: true + +filter: + excluded_paths: + - ./tests + - ./www + paths: + - ./src/* + +build: + image: default-bionic + + environment: + php: + version: 8.0.18 + 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 From a58b3b3ce6894958ff14da8766637ec55dc7c0ff Mon Sep 17 00:00:00 2001 From: Razvan Grigore Date: Wed, 10 Jan 2024 22:18:28 +0200 Subject: [PATCH 4/9] Use latest php version for scrutinizer --- .scrutinizer.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index effa195..2124ec7 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -2,18 +2,18 @@ checks: php: true filter: - excluded_paths: - - ./tests - - ./www paths: - - ./src/* + - src/* + - tests/* + excluded_paths: + - www/* build: image: default-bionic environment: php: - version: 8.0.18 + version: 8.2 ini: xdebug.mode: coverage From 7d6b8f4400ab9da1446f92f9961b4d3c23b7bd4b Mon Sep 17 00:00:00 2001 From: Razvan Grigore Date: Tue, 30 Jan 2024 07:02:24 +0200 Subject: [PATCH 5/9] Add PHP_CodeSniffer --- .github/workflows/lint.yaml | 26 +++++++++++++++++++++++++ .github/workflows/test.yml | 3 +++ README.md | 6 ++++-- phpcs.xml | 38 +++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/lint.yaml create mode 100644 phpcs.xml diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..2717757 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,26 @@ +name: PHP code quality + +on: + push: + branches: + - master + paths-ignore: + - README.md + pull_request: + workflow_dispatch: + +jobs: + run: + 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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a1c32ce..6950d47 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,6 +25,9 @@ jobs: 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 diff --git a/README.md b/README.md index f9e121d..4605d36 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) +[![Build Status](https://scrutinizer-ci.com/g/eymengunay/php-passbook/badges/build.png?b=master)](https://scrutinizer-ci.com/g/eymengunay/php-passbook/build-status/master) [![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 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + /vendor/* + + From 2cdbf69e806ea1709d8ae55a7d33e07dbee56a8d Mon Sep 17 00:00:00 2001 From: Razvan Grigore Date: Tue, 30 Jan 2024 07:52:49 +0200 Subject: [PATCH 6/9] Add PHPStan --- .github/workflows/lint.yaml | 7 +++++-- README.md | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 2717757..494c504 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -1,4 +1,4 @@ -name: PHP code quality +name: Code Quality on: push: @@ -20,7 +20,10 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: '8.2' - tools: cs2pr, phpcs + tools: cs2pr, phpcs, phpstan - name: Run phpcs run: phpcs -q --report=checkstyle . | cs2pr + + - name: Run PHPStan + run: phpstan analyse --level=2 src tests diff --git a/README.md b/README.md index 4605d36..1ef0171 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![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) -[![Build Status](https://scrutinizer-ci.com/g/eymengunay/php-passbook/badges/build.png?b=master)](https://scrutinizer-ci.com/g/eymengunay/php-passbook/build-status/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) From f9c34fc84d378a8b4039c1694685317ab1094b1d Mon Sep 17 00:00:00 2001 From: Razvan Grigore Date: Tue, 30 Jan 2024 07:56:06 +0200 Subject: [PATCH 7/9] Run PHPStan separately --- .github/workflows/lint.yaml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 494c504..a647973 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -10,7 +10,7 @@ on: workflow_dispatch: jobs: - run: + phpcs: runs-on: ubuntu-latest name: PHP_CodeSniffer steps: @@ -20,10 +20,22 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: '8.2' - tools: cs2pr, phpcs, phpstan + 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: Run PHPStan run: phpstan analyse --level=2 src tests From 50ac66455e3474223577024ef56e737e2834a267 Mon Sep 17 00:00:00 2001 From: Razvan Grigore Date: Tue, 30 Jan 2024 10:14:40 +0200 Subject: [PATCH 8/9] Fix all phpcs and phpstan tests --- .github/workflows/lint.yaml | 16 +++- .gitignore | 1 + composer.json | 4 +- phpcs.xml | 5 ++ src/Passbook/ArrayableInterface.php | 6 +- src/Passbook/Certificate/P12Interface.php | 2 +- .../Exception/PassInvalidException.php | 2 +- src/Passbook/Pass.php | 77 +++++++++---------- src/Passbook/Pass/Barcode.php | 12 +-- src/Passbook/Pass/BarcodeInterface.php | 8 +- src/Passbook/Pass/Beacon.php | 5 +- src/Passbook/Pass/BeaconInterface.php | 10 +-- src/Passbook/Pass/DateField.php | 57 ++++++++++++-- src/Passbook/Pass/Field.php | 45 ++++++++--- src/Passbook/Pass/FieldInterface.php | 22 +++--- src/Passbook/Pass/ImageInterface.php | 20 ++++- src/Passbook/Pass/LocalizationInterface.php | 6 +- src/Passbook/Pass/Location.php | 4 +- src/Passbook/Pass/LocationInterface.php | 10 +-- src/Passbook/Pass/Nfc.php | 1 - src/Passbook/Pass/NfcInterface.php | 4 +- src/Passbook/Pass/NumberField.php | 24 +++++- src/Passbook/Pass/StructureInterface.php | 10 +-- src/Passbook/PassFactory.php | 32 ++++---- src/Passbook/PassInterface.php | 32 ++++---- src/Passbook/PassValidator.php | 55 +++++++------ src/Passbook/PassValidatorInterface.php | 1 - src/Passbook/Type/BoardingPass.php | 10 +-- tests/Passbook/Tests/Certificate/P12Test.php | 6 +- tests/Passbook/Tests/Certificate/WWDRTest.php | 6 +- .../Exception/PassInvalidExceptionTest.php | 5 +- tests/Passbook/Tests/Pass/BarcodeTest.php | 2 +- tests/Passbook/Tests/Pass/BeaconTest.php | 2 +- tests/Passbook/Tests/Pass/FieldTest.php | 44 +++++------ tests/Passbook/Tests/Pass/ImageTest.php | 4 +- tests/Passbook/Tests/Pass/LocationTest.php | 2 +- tests/Passbook/Tests/Pass/NumberFieldTest.php | 2 - tests/Passbook/Tests/Pass/StructureTest.php | 10 +-- tests/Passbook/Tests/PassFactoryTest.php | 10 +-- tests/Passbook/Tests/PassTest.php | 4 +- tests/Passbook/Tests/PassValidatorTest.php | 8 +- www/router.php | 18 ++--- 42 files changed, 353 insertions(+), 251 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index a647973..2c3a577 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -37,5 +37,19 @@ jobs: 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=2 src tests + run: phpstan analyse --level=3 src tests 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/composer.json b/composer.json index 01b88ff..fbfbfdc 100644 --- a/composer.json +++ b/composer.json @@ -31,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 index f0c2f7f..bc35bf9 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -33,6 +33,11 @@ + + + + + /vendor/* 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/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 ''; } ?> From 9c7c99d6705ea635262735d7c12bde68031cf51f Mon Sep 17 00:00:00 2001 From: Razvan Grigore Date: Tue, 30 Jan 2024 11:06:41 +0200 Subject: [PATCH 9/9] Add sponsor and contributing info --- .github/FUNDING.yml | 1 + README.md | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .github/FUNDING.yml 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/README.md b/README.md index 1ef0171..f8e578c 100644 --- a/README.md +++ b/README.md @@ -200,9 +200,18 @@ The output should display OK. If not, you need to figure out what's going on and ## Reporting an issue or a feature request Issues and feature requests related to this library are tracked in the Github issue tracker: https://github.com/eymengunay/php-passbook/issues +## Contributing + +Contributions are welcome and will be fully credited. We accept contributions via Pull Requests here on GitHub. + +Please note that this project adhered to [PSR-12 Extended Coding Style Guide](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-12-extended-coding-style-guide.md), so your changes need to: +- Have PHPUnit-test coverage and tests must pass with all supported PHP versions +- Pass PHPStan & PHP_CodeSniffer static analysis checks +- Be documented in `README.md` for any change in behaviour + ## Donating -If you want to support the project, please consider to donate a small amount using my [Gratipay](https://gratipay.com/eymengunay) or [Changetip](http://eymengunay.tip.me) page. Thank you for your support! +If you want to support the project, please consider to donate a small amount using GitHub Sponsors button. Thank you for your support! ## See also [PassbookBundle](https://github.com/eymengunay/PassbookBundle): PHP-Passbook library integration for Symfony2