diff --git a/.gitignore b/.gitignore index 6ea7716..1724f8f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,7 @@ -nbproject -._* -.~lock.* -.buildpath -.DS_Store -.idea -.project -.settings -cache.properties -build -phpunit.xml -composer.lock -vendor/ +/vendor/ +/build/ +/.idea/ + +/composer.lock +/phpunit.xml +/.php_cs.cache diff --git a/.php_cs.dist b/.php_cs.dist index 9e2ed0b..c5c7de6 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -1,23 +1,21 @@ <?php - $header = <<<'EOF' This file is part of the __PACKAGE__ package. @license http://opensource.org/licenses/MIT MIT EOF; - return \PhpCsFixer\Config::create() ->setRiskyAllowed(true) ->setRules(array( '@PSR2' => true, -// 'header_comment' => ['header' => $header, 'commentType' => 'PHPDoc', 'separate' => 'none'], +// 'header_comment' => ['header' => $header, 'commentType' => 'PHPDoc', 'location' =>,'after_declare_strict', 'separate' => 'none'], 'array_syntax' => ['syntax' => 'short'], 'binary_operator_spaces' => ['align_equals' => false, 'align_double_arrow' => false], 'blank_line_after_opening_tag' => true, 'blank_line_after_namespace' => false, 'blank_line_before_return' => true, 'cast_spaces' => true, -// 'class_keyword_remove' => true, +// 'class_keyword_remove' => true, 'combine_consecutive_unsets' => true, 'concat_space' => ['spacing' => 'one'], 'declare_equal_normalize' => true, @@ -30,14 +28,14 @@ return \PhpCsFixer\Config::create() 'heredoc_to_nowdoc' => true, 'include' => true, 'indentation_type' => true, -// 'is_null' => ['use_yoda_style' => false], +// 'is_null' => ['use_yoda_style' => false], 'linebreak_after_opening_tag' => true, 'lowercase_cast' => true, -// 'mb_str_functions' => true, +// 'mb_str_functions' => true, 'method_separation' => true, 'modernize_types_casting' => true, 'native_function_casing' => true, -// 'native_function_invocation' => true, +// 'native_function_invocation' => true, 'new_with_braces' => false, // 'no_alias_functions' => true, 'no_blank_lines_after_class_opening' => true, @@ -52,7 +50,7 @@ return \PhpCsFixer\Config::create() 'no_mixed_echo_print' => ['use' => 'echo'], 'no_multiline_whitespace_around_double_arrow' => true, 'no_multiline_whitespace_before_semicolons' => true, - 'no_php4_constructor' => false, +// 'no_php4_constructor' => true, 'no_short_bool_cast' => true, 'no_short_echo_tag' => false, 'no_singleline_whitespace_before_semicolons' => true, @@ -78,7 +76,7 @@ return \PhpCsFixer\Config::create() 'php_unit_dedicate_assert' => true, 'php_unit_fqcn_annotation' => true, 'php_unit_strict' => true, -// 'phpdoc_add_missing_param_annotation' => true, +// 'phpdoc_add_missing_param_annotation' => true, 'phpdoc_align' => true, 'phpdoc_annotation_without_dot' => true, 'phpdoc_indent' => true, @@ -87,19 +85,19 @@ return \PhpCsFixer\Config::create() 'phpdoc_no_alias_tag' => ['property-read' => 'property', 'property-write' => 'property', 'type' => 'var'], 'phpdoc_no_empty_return' => true, 'phpdoc_no_package' => true, -// 'phpdoc_no_useless_inheritdoc' => true, +// 'phpdoc_no_useless_inheritdoc' => true, 'phpdoc_order' => true, 'phpdoc_return_self_reference' => true, 'phpdoc_scalar' => true, 'phpdoc_separation' => true, 'phpdoc_single_line_var_spacing' => true, -// 'phpdoc_summary' => true, +// 'phpdoc_summary' => true, 'phpdoc_to_comment' => true, 'phpdoc_trim' => true, 'phpdoc_types' => true, 'phpdoc_var_without_name' => true, 'pow_to_exponentiation' => true, -// 'pre_increment' => true, +// 'pre_increment' => true, 'protected_to_private' => true, 'psr0' => true, 'psr4' => true, @@ -107,22 +105,23 @@ return \PhpCsFixer\Config::create() 'return_type_declaration' => ['space_before' => 'one'], 'self_accessor' => true, 'short_scalar_cast' => true, -// 'silenced_deprecation_error' => true, -// 'simplified_null_return' => true, -// 'single_blank_line_before_namespace' => true, +// 'silenced_deprecation_error' => true, +// 'simplified_null_return' => true, + 'single_blank_line_before_namespace' => false, 'single_quote' => true, 'space_after_semicolon' => true, 'standardize_not_equals' => true, -// 'strict_comparison' => true, +// 'strict_comparison' => true, 'ternary_operator_spaces' => true, 'strict_param' => true, 'ternary_to_null_coalescing' => true, -// 'trailing_comma_in_multiline_array' => true, +// 'trailing_comma_in_multiline_array' => true, 'trim_array_spaces' => true, 'unary_operator_spaces' => true, 'whitespace_after_comma_in_array' => true )) + ->setLineEnding("\n") ->setFinder( PhpCsFixer\Finder::create() ->in(__DIR__) - )->setLineEnding("\n"); + ); diff --git a/README.md b/README.md index 08e6742..b923f94 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,10 @@ # A standard PHP project skeleton -(former [php/skeleton](https://packagist.org/packages/php/skeleton)) This project was created in order to provide project skeleton to start new PHP project. Various config files are ready for continuous integration. - - * phpunit.xml.dist for [phpunit](http://phpunit.de/manual/current/en/index.html) - * phpmd.xml for [PHPMD](https://phpmd.org) - * phpcs.xml for [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer/wiki) - * .php_cs for [php-cs-fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer) - * .travis.yml for [Travis CI](https://travis-ci.org/) - * .scrutinizer for [scrutinizer-ci](https://scrutinizer-ci.com/) - * phpstan.neon for [phpstan](https://github.com/phpstan/phpstan) -## Getting started - -### Create project - +## Create Project + ``` composer create-project koriym/php-skeleton {project-path} @@ -26,43 +15,33 @@ What is the vendor name ? What is the package name ? -(MyPackage):AwesomeProject +(MyPackage):AwesomePackage. What is your name ? (Akihito Koriyama): ``` -# Composer scripts +## Composer Commands -## test +### test -`composer test` run [`phpcs`](https://github.com/squizlabs/PHP_CodeSniffer), [`phpmd`](https://github.com/phpmd/phpmd) and [`phpunit`](https://github.com/sebastianbergmann/phpunit). Run `phpunit` for unit test only. +`composer test` run [`phpunit`](https://github.com/sebastianbergmann/phpunit). -``` -composer test -``` +### tests + +`composer tests` run [`phpcs`](https://github.com/squizlabs/PHP_CodeSniffer), [`php-cs-fixer`](https://github.com/FriendsOfPHP/PHP-CS-Fixer), [`phpmd`](https://github.com/phpmd/phpmd), [`phpstan`](https://github.com/phpstan/phpstan) and [`phpunit`](https://github.com/sebastianbergmann/phpunit). -## coverage +### coverage `composer coverage` builds test coverage report. -``` -composer coverage -``` -## cs-fix +### cs-fix `composer cs-fix` run [`php-cs-fixer`](https://github.com/FriendsOfPHP/PHP-CS-Fixer) and [`phpcbf`](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Fixing-Errors-Automatically) to fix up the PHP code to follow the coding standards. (Check only command `compposer cs` is also available.) -``` -composer cs-fix -``` - -## build -`composer build` run [`phploc`](https://github.com/sebastianbergmann/phploc), [`pdepend`](https://pdepend.org/) and `test` above. It's handy for Jenkins. -You need *composer require* `phploc/phploc` and `pdepend/pdepend` for this. +### build -``` -composer build -``` +`composer build` run [`phploc`](https://github.com/sebastianbergmann/phploc), [`pdepend`](https://pdepend.org/) and [tests](#tests) above. It's handy for Jenkins. +You need "composer require phploc/phploc pdepend/pdepend --dev" for this. diff --git a/composer.json b/composer.json index d9c4edd..b36ce31 100644 --- a/composer.json +++ b/composer.json @@ -47,16 +47,28 @@ "Koriym\\PhpSkeleton\\Installer::postInstall", "composer update" ], - "test": ["@cs", "phpmd src text ./phpmd.xml", "phpstan analyse -l max src tests -c phpstan.neon --no-progress", "phpunit"], + "test": ["vendor/bin/phpunit"], + "tests": [ + "@cs", + "vendor/bin/phpmd src,tests text ./phpmd.xml", + "vendor/bin/phpstan analyse -l max src tests -c phpstan.neon --no-progress", + "vendor/bin/phpunit" + ], "coverage": ["php -dzend_extension=xdebug.so ./vendor/bin/phpunit --coverage-text --coverage-html=build/coverage"], - "cs": ["php-cs-fixer fix -v --dry-run", "phpcs --standard=./phpcs.xml src"], - "cs-fix": ["php-cs-fixer fix -v", "phpcbf src"], + "cs": [ + "vendor/bin/php-cs-fixer fix -v --dry-run", + "vendor/bin/phpcs --standard=phpcs.xml src;" + ], + "cs-fix": [ + "vendor/bin/php-cs-fixer fix -v", + "vendor/bin/phpcbf src tests" + ], "build": [ "rm -rf ./build; mkdir -p ./build/logs ./build/pdepend", "pdepend --jdepend-xml=./build/logs/jdepend.xml --jdepend-chart=./build/pdepend/dependencies.svg --overview-pyramid=./build/pdepend/overview-pyramid.svg src", "phploc --log-csv ./build/logs/phploc.csv src", "@cs", - "@test" + "@tests" ] }, "extra": { diff --git a/phpcs.xml b/phpcs.xml index 76dc14b..9fd1652 100755 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,10 +1,8 @@ <?xml version="1.0"?> -<ruleset> - <!-- 2. General --> +<ruleset name="PHP Coding Standards">> <rule ref="Generic.NamingConventions.UpperCaseConstantName"/> <rule ref="Generic.CodeAnalysis.UnusedFunctionParameter"/> <rule ref="Generic.Strings.UnnecessaryStringConcat"/> - <!-- Include the whole PSR-2 standard --> <rule ref="PSR2"> <exclude name="Generic.Files.LineLength"/> </rule> diff --git a/src/Exception/LogicException.php b/src/Exception/LogicException.php index 32966a1..cb959a8 100644 --- a/src/Exception/LogicException.php +++ b/src/Exception/LogicException.php @@ -6,6 +6,9 @@ */ namespace __Vendor__\__Package__\Exception; +/** + * Base Logic Exception class for __Vendor__.__Package__ + */ class LogicException extends \LogicException { } diff --git a/src/Exception/RuntimeException.php b/src/Exception/RuntimeException.php index 2aa037b..e62ec6a 100644 --- a/src/Exception/RuntimeException.php +++ b/src/Exception/RuntimeException.php @@ -6,6 +6,9 @@ */ namespace __Vendor__\__Package__\Exception; +/** + * Base Runtime Exception class for __Vendor__.__Package__ + */ class RuntimeException extends \RuntimeException { } diff --git a/src/Installer.php b/src/Installer.php index 4bd35f1..f0d6685 100644 --- a/src/Installer.php +++ b/src/Installer.php @@ -121,6 +121,7 @@ private static function rename($vendor, $package) $contents = str_replace('__Package__', "{$package}", $contents); $contents = str_replace('__year__', date('Y'), $contents); $contents = str_replace('__name__', self::$name, $contents); + $contents = str_replace('__PackageVarName__', lcfirst($package), $contents); file_put_contents($file, $contents); }; diff --git a/tests/SkeletonTest.php b/tests/SkeletonTest.php index a5dbac4..01c0c09 100644 --- a/tests/SkeletonTest.php +++ b/tests/SkeletonTest.php @@ -1,4 +1,9 @@ <?php +/** + * This file is part of the __Vendor__.__Package__ + * + * @license http://opensource.org/licenses/MIT MIT + */ namespace __Vendor__\__Package__; use PHPUnit\Framework\TestCase; @@ -8,16 +13,16 @@ class __Package__Test extends TestCase /** * @var __Package__ */ - protected $skeleton; + protected $__PackageVarName__; protected function setUp() { - $this->skeleton = new __Package__; + $this->__PackageVarName__ = new __Package__; } - public function testNew() + public function testIsInstanceOf__Package__() { - $actual = $this->skeleton; - $this->assertInstanceOf('\__Vendor__\__Package__\__Package__', $actual); + $actual = $this->__PackageVarName__; + $this->assertInstanceOf(__Package__::class, $actual); } }