diff --git a/README.md b/README.md index 2055cee..1482600 100644 --- a/README.md +++ b/README.md @@ -26,19 +26,19 @@ Composer Schema is documented at . | `license` | Always set to [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0). | | `minimum-stability` | Allow us to specify a single package as `dev` without impacting the other packages, as per `prefer-stable`. | | `prefer-stable` | Always _prefer_ stable versions, even when `minimum-stability` is set to `dev`. | +| `readme` | `README.md` | | `require-dev` | A standard set of packages that are shared across all projects for development purposes. | | `require` | Set the supported PHP versions + any packages that are shared across all projects. Custom sorted as `php` first, then `ext-`, then `lib-`, then other packages. | | `suggest` | Any packages which can be _suggested_ by all projects. Monolog and PSR packages are good examples of this. | | `type` | Always set to `library`. | -### `Makefile` - -There are certain parts of the project `Makefile` which are fairly standardized. Tags (which begin and end with `@@`) are replaced with the latest contents of the templates defined here. +### Static Files -### `.phpcs.dist` +There are certain parts of the project which are fairly standardized. Tags (which begin and end with `@@`) are replaced with the latest contents of the templates defined here. -TBD +* `Makefile` +* `README.md` -### Static Files +### Configuration Files -TBD +* `.phpcs.dist` diff --git a/functions.php b/functions.php index 2fd485d..995066d 100644 --- a/functions.php +++ b/functions.php @@ -109,6 +109,8 @@ function strip_tmpl($s): string function get_tmpl($s): string { $a = explode('.', $s); + $value = array_shift($a); + $value = preg_replace('/^_/', '', $value); - return array_shift($a); + return $value; } diff --git a/static/LICENSE.md.tmpl b/static/LICENSE.md.tmpl new file mode 100644 index 0000000..8d53e9f --- /dev/null +++ b/static/LICENSE.md.tmpl @@ -0,0 +1,141 @@ +# Apache License +Version 2.0, January 2004 + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +## 1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 +through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the +License. + +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled +by, or are under common control with that entity. For the purposes of this definition, "control" means +(i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract +or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial +ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including but not limited to software +source code, documentation source, and configuration files. + +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, +including but not limited to compiled object code, generated documentation, and conversions to other media +types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, +as indicated by a copyright notice that is included in or attached to the work (an example is provided in the +Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) +the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, +as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not +include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work +and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version of the Work and any +modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to +Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to +submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of +electronic, verbal, or written communication sent to the Licensor or its representatives, including but not +limited to communication on electronic mailing lists, source code control systems, and issue tracking systems +that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but +excluding communication that is conspicuously marked or otherwise designated in writing by the copyright +owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been +received by Licensor and subsequently incorporated within the Work. + +## 2. Grant of Copyright License. + +Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare +Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such +Derivative Works in Source or Object form. + +## 3. Grant of Patent License. + +Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent +license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such +license applies only to those patent claims licensable by such Contributor that are necessarily infringed by +their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such +Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim +or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work +constitutes direct or contributory patent infringement, then any patent licenses granted to You under this +License for that Work shall terminate as of the date such litigation is filed. + +## 4. Redistribution. + +You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without +modifications, and in Source or Object form, provided that You meet the following conditions: + + 1. You must give any other recipients of the Work or Derivative Works a copy of this License; and + + 2. You must cause any modified files to carry prominent notices stating that You changed the files; and + + 3. You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, + trademark, and attribution notices from the Source form of the Work, excluding those notices that do + not pertain to any part of the Derivative Works; and + + 4. If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that + You distribute must include a readable copy of the attribution notices contained within such NOTICE + file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed as part of the Derivative Works; within + the Source form or documentation, if provided along with the Derivative Works; or, within a display + generated by the Derivative Works, if and wherever such third-party notices normally appear. The + contents of the NOTICE file are for informational purposes only and do not modify the License. You may + add Your own attribution notices within Derivative Works that You distribute, alongside or as an + addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be + construed as modifying the License. + +You may add Your own copyright statement to Your modifications and may provide additional or different license +terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative +Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the +conditions stated in this License. + +## 5. Submission of Contributions. + +Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by +You to the Licensor shall be under the terms and conditions of this License, without any additional terms or +conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate +license agreement you may have executed with Licensor regarding such Contributions. + +## 6. Trademarks. + +This License does not grant permission to use the trade names, trademarks, service marks, or product names of +the Licensor, except as required for reasonable and customary use in describing the origin of the Work and +reproducing the content of the NOTICE file. + +## 7. Disclaimer of Warranty. + +Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor +provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, +MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the +appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of +permissions under this License. + +## 8. Limitation of Liability. + +In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless +required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any +Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential +damages of any character arising as a result of this License or out of the use or inability to use the Work +(including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or +any and all other commercial damages or losses), even if such Contributor has been advised of the possibility +of such damages. + +## 9. Accepting Warranty or Additional Liability. + +While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, +acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this +License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole +responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold +each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason +of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS diff --git a/static/_bettercodehub.yml.tmpl b/static/_bettercodehub.yml.tmpl new file mode 100644 index 0000000..52e8783 --- /dev/null +++ b/static/_bettercodehub.yml.tmpl @@ -0,0 +1,6 @@ +component_depth: 1 +languages: + - php +exclude: + - /docs/.* + - /docs/src/.* diff --git a/static/_coveralls.yml.tmpl b/static/_coveralls.yml.tmpl new file mode 100644 index 0000000..dabeb65 --- /dev/null +++ b/static/_coveralls.yml.tmpl @@ -0,0 +1,3 @@ +service_name: travis-ci +coverage_clover: tests/report/clover.xml +json_path: tests/report/coveralls-upload.json diff --git a/static/_editorconfig.tmpl b/static/_editorconfig.tmpl new file mode 100644 index 0000000..42b916b --- /dev/null +++ b/static/_editorconfig.tmpl @@ -0,0 +1,19 @@ +# EditorConfig is awesome: http://EditorConfig.org + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +end_of_line = lf +insert_final_newline = true +charset = utf-8 + +# 4 space indentation +[*.{php,xml,yml,json,dist}] +indent_style = space +indent_size = 4 + +# Tab indentation (no size specified) +[Makefile*] +indent_style = tab diff --git a/static/_gitignore.tmpl b/static/_gitignore.tmpl new file mode 100644 index 0000000..39760d4 --- /dev/null +++ b/static/_gitignore.tmpl @@ -0,0 +1,10 @@ +.php_cs.cache +.phpintel/ +.phpunit.result.cache +bin/ +docs/_build/ +docs/_cache/ +reports/ +sandbox.php +tests/report/ +vendor/ diff --git a/static/_scrutinizer.yml.tmpl b/static/_scrutinizer.yml.tmpl new file mode 100644 index 0000000..37a268f --- /dev/null +++ b/static/_scrutinizer.yml.tmpl @@ -0,0 +1,192 @@ +# language: php + +before_commands: + - "composer install --no-dev --prefer-source" +checks: + php: + verify_property_names: true + verify_argument_usable_as_reference: true + verify_access_scope_valid: true + variable_existence: true + useless_calls: true + use_statement_alias_conflict: true + use_self_instead_of_fqcn: true + uppercase_constants: true + unused_variables: true + unused_properties: true + unused_parameters: true + unused_methods: true + unreachable_code: true + too_many_arguments: true + symfony_request_injection: true + switch_fallthrough_commented: true + spacing_of_function_arguments: true + spacing_around_non_conditional_operators: true + spacing_around_conditional_operators: true + space_after_cast: true + single_namespace_per_use: true + simplify_boolean_return: true + side_effects_or_types: true + security_vulnerabilities: true + scope_indentation: + spaces_per_level: '4' + return_doc_comments: true + return_doc_comment_if_not_inferrable: true + require_scope_for_properties: true + require_scope_for_methods: true + require_php_tag_first: true + require_braces_around_control_structures: true + remove_trailing_whitespace: true + remove_php_closing_tag: true + psr2_switch_declaration: true + psr2_control_structure_declaration: true + psr2_class_declaration: true + property_assignments: true + prefer_unix_line_ending: true + prefer_sapi_constant: true + precedence_mistakes: true + precedence_in_conditions: true + phpunit_assertions: true + php5_style_constructor: true + parameter_non_unique: true + parameter_doc_comments: true + param_doc_comment_if_not_inferrable: true + overriding_private_members: true + optional_parameters_at_the_end: true + one_class_per_file: true + no_unnecessary_if: true + no_unnecessary_function_call_in_for_loop: true + no_unnecessary_final_modifier: true + no_underscore_prefix_in_properties: true + no_underscore_prefix_in_methods: true + no_trait_type_hints: true + no_trailing_whitespace: true + no_space_inside_cast_operator: true + no_space_before_semicolon: true + no_short_open_tag: true + no_short_method_names: + minimum: '3' + no_property_on_interface: true + no_non_implemented_abstract_methods: true + no_mixed_inline_html: true + no_long_variable_names: + maximum: '40' + no_goto: true + no_global_keyword: true + no_exit: true + no_eval: true + no_empty_statements: true + no_else_if_statements: true + no_duplicate_arguments: true + no_debug_code: true + newline_at_end_of_file: true + naming_conventions: + local_variable: '^[a-z][a-zA-Z0-9_]*$' + abstract_class_name: ^Abstract|Factory$ + utility_class_name: 'Utils?$' + constant_name: '^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$' + property_name: '^[a-z][a-zA-Z0-9_]*$' + method_name: '^(?:[a-z]|__)[a-zA-Z0-9]*$' + parameter_name: '^[a-z][a-zA-Z0-9_]*$' + interface_name: '^[A-Z][a-zA-Z0-9]*Interface$' + type_name: '^[A-Z][a-zA-Z0-9]*$' + exception_name: '^[A-Z][a-zA-Z0-9]*Exception$' + isser_method_name: '^(?:is|has|should|may|supports)' + more_specific_types_in_doc_comments: true + missing_arguments: true + method_calls_on_non_object: true + lowercase_php_keywords: true + lowercase_basic_constants: true + line_length: + max_length: '120' + instanceof_class_exists: true + function_in_camel_caps: true + function_body_start_on_new_line: true + foreach_usable_as_reference: true + foreach_traversable: true + fix_use_statements: + remove_unused: true + preserve_multiple: false + preserve_blanklines: false + order_alphabetically: true + fix_php_opening_tag: true + fix_linefeed: true + fix_line_ending: true + fix_identation_4spaces: true + fix_doc_comments: true + ensure_lower_case_builtin_functions: true + encourage_single_quotes: true + encourage_shallow_comparison: true + encourage_postdec_operator: true + duplication: true + deprecated_code_usage: true + deadlock_detection_in_loops: true + code_rating: true + closure_use_not_conflicting: true + closure_use_modifiable: true + classes_in_camel_caps: true + catch_class_exists: true + blank_line_after_namespace_declaration: true + avoid_useless_overridden_methods: true + avoid_usage_of_logical_operators: true + avoid_unnecessary_concatenation: true + avoid_tab_indentation: true + avoid_superglobals: true + avoid_perl_style_comments: true + avoid_multiple_statements_on_same_line: true + avoid_length_functions_in_loops: true + avoid_fixme_comments: true + avoid_duplicate_types: true + avoid_corrupting_byteorder_marks: true + avoid_conflicting_incrementers: true + avoid_closing_tag: true + avoid_aliased_php_functions: true + assignment_of_null_return: true + argument_type_checks: true + align_assignments: true +tools: + external_code_coverage: + timeout: 600 + php_sim: false + php_code_coverage: + enabled: true + php_code_sniffer: + enabled: true + config: + standard: PSR2 + filter: + paths: ["src/*", "tests/*"] + php_cs_fixer: + enabled: true + config: + level: all + filter: + paths: ["src/*", "tests/*"] + php_cpd: + enabled: true + excluded_dirs: ["docs", "tests", "vendor"] + php_loc: + enabled: true + excluded_dirs: ["docs", "tests", "vendor"] + php_mess_detector: + config: + code_size_rules: + cyclomatic_complexity: true + unused_code_rules: + unused_local_variable: true + unused_private_method: true + unused_formal_parameter: true + php_pdepend: + enabled: true + excluded_dirs: ["docs", "tests", "vendor"] + php_analyzer: + enabled: true + filter: + paths: ["src/*", "tests/*"] + sensiolabs_security_checker: true + php_hhvm: + enabled: false +filter: + excluded_paths: + - 'docs/*' + - 'tests/*' diff --git a/static/pdepend.xml.dist.tmpl b/static/pdepend.xml.dist.tmpl new file mode 100644 index 0000000..f2001bf --- /dev/null +++ b/static/pdepend.xml.dist.tmpl @@ -0,0 +1,18 @@ + + + + + + Arial + 12 + + + + memory + + + + diff --git a/static/phpcs.xml.tmpl b/static/phpcs.xml.tmpl new file mode 100644 index 0000000..8ba6ad4 --- /dev/null +++ b/static/phpcs.xml.tmpl @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/static/phpmd.xml.dist.tmpl b/static/phpmd.xml.dist.tmpl new file mode 100644 index 0000000..33188e9 --- /dev/null +++ b/static/phpmd.xml.dist.tmpl @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/static/phpmetrics.yml.tmpl b/static/phpmetrics.yml.tmpl new file mode 100644 index 0000000..8affcbc --- /dev/null +++ b/static/phpmetrics.yml.tmpl @@ -0,0 +1,24 @@ +myconfig: + # paths to explore + path: + extensions: php + exclude: tests + + # report and violations files + logging: + report: + xml: ./reports/metrics/phpmetrics.xml + html: ./reports/metrics/phpmetrics.html + json: ./reports/metrics/phpmetrics.json + violations: + xml: ./reports/metrics/violations.xml + chart: + bubbles: ./reports/metrics/bubbles.svg + + # condition of failure + failure: average.maintainabilityIndex < 50 or sum.loc > 10000 + + # rules used for color ([ critical, warning, good ]) + rules: + cyclomaticComplexity: [ 10, 6, 2 ] + maintainabilityIndex: [ 0, 69, 85 ] diff --git a/templates/PHP_CS-HEADER.tmpl b/templates/PHP_CS-HEADER.tmpl new file mode 100644 index 0000000..9e14f15 --- /dev/null +++ b/templates/PHP_CS-HEADER.tmpl @@ -0,0 +1,5 @@ +/** + * Defintions can be looked-up at . + * + * Rules current as of https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/2.15/README.rst + */ diff --git a/templates/PHP_CS-RULES.tmpl b/templates/PHP_CS-RULES.tmpl new file mode 100644 index 0000000..a4d0616 --- /dev/null +++ b/templates/PHP_CS-RULES.tmpl @@ -0,0 +1,506 @@ +return Config::create() + ->setIndent(" ") + ->setLineEnding("\n") + ->setRiskyAllowed(true) + ->setRules([ + // Configurable + 'align_multiline_comment' => [ + 'comment_type' => 'all_multiline', + ], + 'array_syntax' => [ + 'syntax' => 'short', + ], + 'binary_operator_spaces'=> [ + 'default' => 'align_single_space_minimal', + 'operators' => [ + '=' => 'align_single_space_minimal', + '=>' => 'align_single_space_minimal', + ], + ], + 'blank_line_before_statement' => [ + 'statements' => [ + 'break', + 'case', + 'continue', + 'declare', + 'default', + 'die', + 'do', + 'exit', + 'for', + 'foreach', + 'if', + 'return', + 'switch', + 'throw', + 'try', + 'while', + 'yield', + ], + ], + 'braces' => [ + 'allow_single_line_closure' => false, + 'position_after_anonymous_constructs' => 'same', + 'position_after_control_structures' => 'same', + 'position_after_functions_and_oop_constructs' => 'next', + ], + 'cast_spaces' => [ + 'space' => 'single', + ], + 'class_definition' => [ + 'multiLineExtendsEachSingleLine' => false, + 'singleItemSingleLine' => true, + 'singleLine' => true, + ], + 'class_attributes_separation' => [ + 'elements' => [ + 'const', + 'method', + 'property', + ], + ], + 'concat_space' => [ + 'spacing' => 'one', + ], + 'declare_equal_normalize' => [ + 'space' => 'none', + ], + 'escape_implicit_backslashes' => [ + 'double_quoted' => true, + 'heredoc_syntax' => true, + 'single_quoted' => false, + ], + 'error_suppression' => [ + 'mute_deprecation_error' => false, + 'noise_remaining_usages' => true, + 'noise_remaining_usages_exclude' => [], + ], + 'final_internal_class' => [ + 'annotation-black-list' => [], + 'annotation-white-list' => [ + '@internal', + ], + 'consider-absent-docblock-as-internal-class' => false, + ], + 'fopen_flags' => [ + 'b_mode' => true, + ], + 'function_declaration' => [ + 'closure_function_spacing' => 'one', + ], + 'function_to_constant' => [ + 'functions' => [ + // 'get_called_class', + 'get_class', + 'phpversion', + 'php_sapi_name', + 'pi', + ], + ], + 'general_phpdoc_annotation_remove' => [ + 'annotations' => [ + 'author', + 'package', + 'subpackage', + ], + ], + 'header_comment' => [ + 'commentType' => 'PHPDoc', + 'location' => 'after_open', + 'separate' => 'bottom', + 'header' => $fileHeader, + ], + 'increment_style' => [ + 'style' => 'post', + ], + 'is_null' => [ + 'use_yoda_style' => true, + ], + 'list_syntax' => [ + 'syntax' => 'short', + ], + 'method_argument_space' => [ + 'after_heredoc' => false, + 'ensure_fully_multiline' => true, + 'keep_multiple_spaces_after_comma' => false, + 'on_multiline' => 'ignore', + ], + 'multiline_whitespace_before_semicolons' => [ + 'strategy' => 'no_multi_line', + ], + 'native_constant_invocation' => [ + 'exclude' => [ + 'null', + 'false', + 'true', + ], + 'fix_built_in' => true, + 'include' => [], + 'scope' => 'all', + ], + 'native_function_invocation' => [ + 'exclude' => [], + 'include' => [ + '@internal', + ], + 'scope' => 'all', + 'strict' => true, + ], + 'no_alias_functions' => [ + 'sets' => [ + '@all', + ], + ], + 'no_break_comment' => [ + 'comment_text' => 'no break', + ], + 'no_extra_blank_lines' => [ + 'tokens' => [ + 'break', + 'case', + 'continue', + 'curly_brace_block', + 'default', + 'extra', + 'parenthesis_brace_block', + 'return', + 'square_brace_block', + 'switch', + 'throw', + 'use', + 'useTrait', + 'use_trait', + ], + ], + 'no_mixed_echo_print' => [ + 'use' => 'echo', + ], + 'no_spaces_around_offset' => [ + 'positions' => [ + 'inside', + 'outside' + ], + ], + 'no_superfluous_phpdoc_tags' => [ + 'allow_mixed' => false, + ], + 'no_unneeded_control_parentheses' => [ + 'statements' => [ + 'break', + 'clone', + 'continue', + 'echo_print', + 'return', + 'switch_case', + 'yield', + ], + ], + 'non_printable_character' => [ + 'use_escape_sequences_in_strings' => false, + ], + 'ordered_class_elements' => [ + 'sortAlgorithm' => 'none', + 'order' => [ + 'use_trait', + 'constant_public', + 'constant_protected', + 'constant_private', + 'property_public_static', + 'property_public', + 'property_protected_static', + 'property_protected', + 'property_private_static', + 'property_private', + 'construct', + 'destruct', + 'magic', + 'phpunit', + 'method_public_static', + 'method_public', + 'method_protected_static', + 'method_protected', + 'method_private_static', + 'method_private', + ], + ], + 'ordered_imports' => [ + 'importsOrder' => null, + 'sortAlgorithm' => 'alpha', + ], + 'ordered_interfaces' => [ + 'direction' => 'ascend', + 'order' => 'alpha', + ], + 'php_unit_construct' => [ + 'assertions' => [ + 'assertEquals', + 'assertSame', + 'assertNotEquals', + 'assertNotSame', + ], + ], + 'php_unit_dedicate_assert' => [ + 'target' => 'newest', + ], + 'php_unit_dedicate_assert_internal_type' => [ + 'target' => 'newest', + ], + 'php_unit_expectation' => [ + 'target' => 'newest', + ], + 'php_unit_method_casing' => [ + 'case' => 'camel_case', + ], + 'php_unit_namespaced' => [ + 'target' => 'newest', + ], + 'php_unit_no_expectation_annotation' => [ + 'target' => 'newest', + 'use_class_const' => true, + ], + 'php_unit_test_annotation' => [ + 'style' => 'prefix', + ], + 'php_unit_test_case_static_method_calls' => [ + 'call_type' => 'static', + 'methods' => [], + ], + 'phpdoc_no_alias_tag' => [ + 'property-read' => 'property', + 'property-write' => 'property', + 'type' => 'var', + 'link' => 'see', + ], + 'phpdoc_add_missing_param_annotation' => [ + 'only_untyped' => false, + ], + 'phpdoc_align' => [ + 'align' => 'vertical', + 'tags' => [ + 'param', + 'return', + 'throws', + 'type', + 'var', + ], + ], + 'phpdoc_return_self_reference' => [ + 'replacements' => [ + 'this' => '$this', + '@this' => '$this', + '$self' => 'self', + '@self' => 'self', + '$static' => 'static', + '@static' => 'static', + ], + ], + 'phpdoc_scalar' => [ + 'types' => [ + 'boolean', + 'callback', + 'double', + 'integer', + 'real', + 'str', + ], + ], + 'phpdoc_types' => [ + 'groups' => [ + 'simple', + 'alias', + 'meta', + ], + ], + 'phpdoc_types_order' => [ + 'null_adjustment' => 'always_last', + 'sort_algorithm' => 'alpha', + ], + 'random_api_migration' => [ + 'replacements' => [ + 'getrandmax' => 'mt_getrandmax', + 'mt_rand' => 'random_int', + 'rand' => 'random_int', + 'srand' => 'random_int', + ], + ], + 'return_type_declaration' => [ + 'space_before' => 'none', + ], + 'single_class_element_per_statement' => [ + 'elements' => [ + 'const', + 'property', + ], + ], + 'single_line_comment_style' => [ + 'comment_types' => [ + 'asterisk', + 'hash', + ], + ], + 'single_quote' => [ + 'strings_containing_single_quote_chars' => false, + ], + 'space_after_semicolon' => [ + 'remove_in_empty_for_expressions' => false, + ], + 'visibility_required' => [ + 'const', + 'method', + 'property', + ], + 'yoda_style' => [ + 'always_move_variable' => false, + 'equal' => true, + 'identical' => true, + 'less_and_greater' => false, + ], + + // Enforce + 'array_indentation' => true, + 'backtick_to_shell_exec' => true, + 'blank_line_after_namespace' => true, + 'blank_line_after_opening_tag' => true, + 'combine_consecutive_issets' => true, + 'combine_consecutive_unsets' => true, + 'combine_nested_dirname' => true, + 'compact_nullable_typehint' => true, + 'declare_strict_types' => true, + 'dir_constant' => true, + 'elseif' => true, + 'encoding' => true, + 'ereg_to_preg' => true, + 'explicit_indirect_variable' => true, + 'explicit_string_variable' => true, + 'fopen_flag_order' => true, + 'full_opening_tag' => true, + 'fully_qualified_strict_types' => true, + 'function_typehint_space' => true, + 'heredoc_to_nowdoc' => true, + 'implode_call' => true, + 'include' => true, + 'indentation_type' => true, + 'line_ending' => true, + 'linebreak_after_opening_tag' => true, + 'logical_operators' => true, + 'lowercase_cast' => true, + 'lowercase_constants' => true, + 'lowercase_keywords' => true, + 'lowercase_static_reference' => true, + 'magic_constant_casing' => true, + 'magic_method_casing' => true, + 'mb_str_functions' => true, + 'method_chaining_indentation' => true, + 'modernize_types_casting' => true, + 'multiline_comment_opening_closing' => true, + 'native_function_casing' => true, + 'native_function_type_declaration_casing' => true, + 'new_with_braces' => true, + 'no_alternative_syntax' => true, + 'no_binary_string' => true, + 'no_blank_lines_after_class_opening' => true, + 'no_blank_lines_after_phpdoc' => true, + 'no_closing_tag' => true, + 'no_empty_comment' => true, + 'no_empty_phpdoc' => true, + 'no_empty_statement' => true, + 'no_homoglyph_names' => true, + 'no_leading_import_slash' => true, + 'no_leading_namespace_whitespace' => true, + 'no_multiline_whitespace_around_double_arrow' => true, + 'no_null_property_initialization' => true, + 'no_php4_constructor' => true, + 'no_short_bool_cast' => true, + 'no_singleline_whitespace_before_semicolons' => true, + 'no_spaces_after_function_name' => true, + 'no_spaces_inside_parenthesis' => true, + 'no_superfluous_elseif' => true, + 'no_trailing_comma_in_list_call' => true, + 'no_trailing_comma_in_singleline_array' => true, + 'no_trailing_whitespace' => true, + 'no_trailing_whitespace_in_comment' => true, + 'no_unneeded_curly_braces' => true, + 'no_unneeded_final_method' => true, + 'no_unreachable_default_argument_value' => true, + 'no_unset_on_property' => true, + 'no_unused_imports' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'no_whitespace_before_comma_in_array' => true, // @todo review + 'no_whitespace_in_blank_line' => true, + 'normalize_index_brace' => true, + 'object_operator_without_whitespace' => true, + 'php_unit_fqcn_annotation' => true, + 'php_unit_mock' => true, + 'php_unit_mock_short_will_return' => true, + 'php_unit_set_up_tear_down_visibility' => true, + 'phpdoc_indent' => true, + 'phpdoc_inline_tag' => true, + 'phpdoc_no_access' => true, + 'phpdoc_no_empty_return' => true, + 'phpdoc_no_package' => true, + 'phpdoc_no_useless_inheritdoc' => true, + 'phpdoc_order' => true, + 'phpdoc_separation' => true, + 'phpdoc_single_line_var_spacing' => true, + 'phpdoc_summary' => true, + 'phpdoc_to_comment' => true, + 'phpdoc_trim' => true, + 'phpdoc_trim_consecutive_blank_line_separation' => true, + 'phpdoc_var_annotation_correct_order' => true, + 'phpdoc_var_without_name' => true, + 'pow_to_exponentiation' => true, + 'psr4' => true, + 'return_assignment' => true, + 'self_accessor' => true, + 'semicolon_after_instruction' => true, + 'set_type_to_cast' => true, + 'short_scalar_cast' => true, + 'simple_to_complex_string_variable' => true, + 'simplified_null_return' => true, + 'single_blank_line_at_eof' => true, + 'single_blank_line_before_namespace' => true, + 'single_import_per_statement' => true, + 'single_line_after_imports' => true, + 'single_trait_insert_per_statement' => true, + 'standardize_increment' => true, + 'standardize_not_equals' => true, + 'static_lambda' => true, + 'strict_comparison' => true, + 'strict_param' => true, + 'string_line_ending' => true, + 'switch_case_semicolon_to_colon' => true, + 'switch_case_space' => true, + 'ternary_operator_spaces' => true, + 'ternary_to_null_coalescing' => true, + 'trailing_comma_in_multiline_array' => true, // @todo review + 'trim_array_spaces' => true, + 'unary_operator_spaces' => true, + 'void_return' => true, + 'whitespace_after_comma_in_array' => true, + + // Do not enforce + 'class_keyword_remove' => false, + 'comment_to_phpdoc' => false, + 'date_time_immutable' => false, + 'doctrine_annotation_braces' => false, + 'doctrine_annotation_indentation' => false, + 'doctrine_annotation_spaces' => false, + 'final_class' => false, + 'heredoc_indentation' => false, // @todo 7.3 + 'no_blank_lines_before_namespace' => false, + 'no_short_echo_tag' => false, + 'no_unset_cast' => false, + 'not_operator_with_space' => false, + 'not_operator_with_successor_space' => false, + 'php_unit_strict' => false, + 'php_unit_test_class_requires_covers' => false, + 'php_unit_size_class' => false, + 'phpdoc_annotation_without_dot' => false, + 'phpdoc_to_return_type' => false, + 'protected_to_private' => false, + 'psr0' => false, + ]) + ->setFinder($finder) + ->setUsingCache(true) +; diff --git a/unify b/unify index 8ecbada..1ecf95a 100755 --- a/unify +++ b/unify @@ -15,6 +15,7 @@ use Symfony\Component\Finder\Finder; $__files__ = [ 'README.md.tmpl', 'Makefile.tmpl', + '_php_cs.dist.tmpl', ]; foreach ($__files__ as $__f__) { @@ -34,7 +35,7 @@ foreach ($__files__ as $__f__) { dirname( dirname($file->getRealPath()) ), - strip_tmpl($__f__) + preg_replace('/^_/', '.', strip_tmpl($__f__)) ); echo sprintf('Updating %s', $writeTo) . PHP_EOL; diff --git a/unify-static b/unify-static new file mode 100755 index 0000000..1c41a00 --- /dev/null +++ b/unify-static @@ -0,0 +1,47 @@ +#! /usr/bin/env php +ignoreDotFiles(false) + ->files() + ->name('.lang-php') + ->depth('< 2') + ->in(dirname(__DIR__)) + ->notPath('vendor') +; + +$statics = Finder::create() + ->files() + ->name('*.tmpl') + ->depth('< 1') + ->in(__DIR__ . '/static') +; + +foreach ($statics as $static) { + $source = $static->getRealPath(); + $destFile = preg_replace('/^_/', '.', strip_tmpl($static->getFilename())); + + // Read the content from disk once + $content = file_get_contents($source); + echo sprintf('Reading from %s…', $source) . PHP_EOL; + + // Write the content multiple times + foreach ($finder as $file) { + $dirRoot = dirname($file->getRealPath()); + $dirPath = sprintf('%s/%s', $dirRoot, $destFile); + file_put_contents($dirPath, $content); + + echo sprintf('Writing to %s…', $dirPath) . PHP_EOL; + } +}