Skip to content

Commit

Permalink
Merge pull request #38 from koriym/1.0
Browse files Browse the repository at this point in the history
Version 1.0
  • Loading branch information
koriym authored Apr 13, 2018
2 parents e33941e + 6de0b3d commit 5a0954d
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 78 deletions.
20 changes: 7 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
35 changes: 17 additions & 18 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -87,42 +85,43 @@ 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,
'random_api_migration' => true,
'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");
);
49 changes: 14 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -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}
Expand All @@ -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.
20 changes: 16 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 1 addition & 3 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
3 changes: 3 additions & 0 deletions src/Exception/LogicException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
*/
namespace __Vendor__\__Package__\Exception;

/**
* Base Logic Exception class for __Vendor__.__Package__
*/
class LogicException extends \LogicException
{
}
3 changes: 3 additions & 0 deletions src/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
*/
namespace __Vendor__\__Package__\Exception;

/**
* Base Runtime Exception class for __Vendor__.__Package__
*/
class RuntimeException extends \RuntimeException
{
}
1 change: 1 addition & 0 deletions src/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
15 changes: 10 additions & 5 deletions tests/SkeletonTest.php
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
}

0 comments on commit 5a0954d

Please sign in to comment.