Skip to content

Commit

Permalink
Merge pull request #101 from koriym/clean
Browse files Browse the repository at this point in the history
Clean the code
  • Loading branch information
koriym authored Oct 5, 2016
2 parents 773b3ea + fa9eb37 commit 2d6a47a
Show file tree
Hide file tree
Showing 16 changed files with 149 additions and 119 deletions.
3 changes: 3 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ $config = Symfony\CS\Config\Config::create()
'no_blank_lines_after_class_opening',
'no_empty_lines_after_phpdocs',
'operators_spaces',
'duplicate_semicolon',
'namespace_no_leading_whitespace',
'phpdoc_indent',
'phpdoc_no_empty_return',
'phpdoc_no_package',
Expand All @@ -23,6 +25,7 @@ $config = Symfony\CS\Config\Config::create()
'remove_lines_between_uses',
'return',
'single_array_no_trailing_comma',
'single_quote',
'spaces_before_semicolon',
'spaces_cast',
'standardize_not_equal',
Expand Down
12 changes: 7 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
sudo: false
language: php
php:
- 5.5
- 5.6
- 7.0
- hhvm
- 7
sudo: false
cache:
directories:
- $HOME/.composer/cache
before_script:
- composer self-update
- composer install
script:
- phpunit --coverage-clover=coverage.clover
- phpunit
after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
- if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
36 changes: 17 additions & 19 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
Copyright (c) 2012-2016, Akihito Koriyama <[email protected]>
All rights reserved.
The MIT License (MIT)

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Copyright (c) 2012-2016 Akihito Koriyama

- Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
22 changes: 22 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,27 @@
"psr-4": {
"BEAR\\Sunday\\": "src/"
}
},
"autoload-dev": {
"files": ["tests/functions.php"]
},
"scripts" :{
"test": [
"phpmd src text ./phpmd.xml",
"phpcs src tests",
"phpunit"
],
"cs-fix": [
"php-cs-fixer fix --config-file=./.php_cs",
"phpcbf src"
],
"build": [
"rm -rf ./build; mkdir -p ./build/logs ./build/pdepend ./build/api",
"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",
"phpcs --report=checkstyle --report-file=./build/logs/checkstyle.xml --standard=phpcs.xml src",
"apigen generate -s src -d build/api",
"@test"
]
}
}
9 changes: 2 additions & 7 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
<?xml version="1.0"?>
<ruleset>
<description>The coding standard used for applications using BEAR.Sunday Framework.</description>
<!-- 2. General -->
<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"/>
<exclude name="PSR2.Classes.PropertyDeclaration.Underscore"/>
<exclude name="PSR2.Methods.MethodDeclaration.Underscore"/>
</rule>
<rule ref="PEAR.Commenting.FunctionComment">
<exclude name="PEAR.Commenting.FunctionComment.MissingReturn"/>
<exclude name="PEAR.Commenting.FunctionComment.MissingParamComment"/>
<exclude name="PEAR.Commenting.FunctionComment.SpacingBeforeTags"/>
<exclude name="PEAR.Commenting.FunctionComment.MissingParamTag"/>
<exclude name="PEAR.Commenting.FunctionComment.Missing"/>
<exclude name="PEAR.Commenting.FunctionComment.MissingReturn"/>
<exclude name="PEAR.Commenting.FunctionComment.ParameterCommentsNotAligned"/>
<exclude name="PEAR.Commenting.FileComment.Missing"/>
</rule>
<file>src</file>
<file>tests</file>
</ruleset>
33 changes: 14 additions & 19 deletions phpmd.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
<ruleset
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<!--codesize-->
<rule ref="rulesets/codesize.xml/CyclomaticComplexity">
<properties>
<property name="reportLevel" value="20"/>
</properties>
</rule>
<rule ref="rulesets/codesize.xml/NPathComplexity">
<properties>
<property name="minimum" value="200"/>
</properties>
</rule>
<rule ref="rulesets/codesize.xml/ExcessiveClassComplexity">
<properties>
<property name="maximum" value="100"/>
</properties>
</rule>
<rule ref="rulesets/codesize.xml/CyclomaticComplexity"/>
<rule ref="rulesets/codesize.xml/NPathComplexity"/>
<rule ref="rulesets/codesize.xml/ExcessiveClassComplexity"/>
<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>
<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>
<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>
Expand All @@ -28,10 +16,14 @@
<!--design-->
<rule ref="rulesets/design.xml/EvalExpression"/>
<rule ref="rulesets/design.xml/ExitExpression"/>
<rule ref="rulesets/design.xml/GotoStatement" />
<rule ref="rulesets/design.xml/GotoStatement"/>
<rule ref="rulesets/design.xml/NumberOfChildren"/>
<rule ref="rulesets/design.xml/DepthOfInheritance"/>
<!-- <rule ref="rulesets/design.xml/CouplingBetweenObjects" /> -->
<rule ref="rulesets/design.xml/CouplingBetweenObjects">
<properties>
<property name="minimum" value="14"/>
</properties>
</rule>
<!--naming-->
<rule ref="rulesets/naming.xml/ConstantNamingConventions"/>
<rule ref="rulesets/naming.xml/BooleanGetMethodName"/>
Expand All @@ -41,10 +33,13 @@
<rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/>
<rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/>
<!--controversial-->
<rule ref="rulesets/controversial.xml/Superglobals"/>
<rule ref="rulesets/controversial.xml/CamelCaseClassName"/>
<rule ref="rulesets/controversial.xml/CamelCasePropertyName"/>
<rule ref="rulesets/controversial.xml/CamelCaseMethodName"/>
<rule ref="rulesets/controversial.xml/CamelCaseParameterName"/>
<rule ref="rulesets/controversial.xml/CamelCaseVariableName"/>
<!--cleancode-->
<rule ref="rulesets/cleancode.xml/BooleanArgumentFlag"/>
<!-- <rule ref="rulesets/cleancode.xml/ElseExpression" /> -->
<rule ref="rulesets/cleancode.xml/ElseExpression"/>
</ruleset>
36 changes: 36 additions & 0 deletions tests/Fake/Inject/DummyLogger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace BEAR\Sunday\Inject;

use Psr\Log\LoggerInterface;

class DummyLogger implements LoggerInterface
{
public function emergency($message, array $context = [])
{
}
public function alert($message, array $context = [])
{
}
public function critical($message, array $context = [])
{
}
public function error($message, array $context = [])
{
}
public function warning($message, array $context = [])
{
}
public function notice($message, array $context = [])
{
}
public function info($message, array $context = [])
{
}
public function debug($message, array $context = [])
{
}
public function log($level, $message, array $context = [])
{
}
}
13 changes: 13 additions & 0 deletions tests/Fake/Inject/PsrLoggerApplication.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace BEAR\Sunday\Inject;

class PsrLoggerApplication
{
use PsrLoggerInject;

public function returnDependency()
{
return $this->logger;
}
}
13 changes: 13 additions & 0 deletions tests/Fake/Inject/PsrLoggerModule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace BEAR\Sunday\Inject;

use Ray\Di\AbstractModule;

class PsrLoggerModule extends AbstractModule
{
protected function configure()
{
$this->bind('Psr\Log\LoggerInterface')->to(__NAMESPACE__ . '\DummyLogger');
}
}
13 changes: 13 additions & 0 deletions tests/Fake/Inject/ResourceInjectApplication.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace BEAR\Sunday\Inject;

class ResourceInjectApplication
{
use ResourceInject;

public function returnDependency()
{
return $this->resource;
}
}
3 changes: 0 additions & 3 deletions tests/Fake/Provide/Transfer/FakeHttpResponder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

use BEAR\Resource\ResourceObject;

require_once __DIR__ . '/header.php';
require_once __DIR__ . '/http_response_code.php';

class FakeHttpResponder extends HttpResponder
{
public static $code;
Expand Down
9 changes: 4 additions & 5 deletions tests/Fake/Provide/Transfer/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
*/
namespace BEAR\Sunday\Provide\Transfer;

function header(
$string,
$replace = true,
$http_response_code = null
) {
function header($string, $replace = true, $http_response_code = null)
{
FakeHttpResponder::$headers[] = func_get_args();

unset($string, $replace, $http_response_code);
}
1 change: 1 addition & 0 deletions tests/Fake/Provide/Transfer/http_response_code.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
function http_response_code($int)
{
FakeHttpResponder::$code = func_get_args();
unset($int);
}
51 changes: 0 additions & 51 deletions tests/Inject/PsrLoggerInjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,8 @@

namespace BEAR\Sunday\Inject;

use Psr\Log\LoggerInterface;
use Ray\Di\AbstractModule;
use Ray\Di\Injector;

class PsrLoggerApplication
{
use PsrLoggerInject;

public function returnDependency()
{
return $this->logger;
}
}

class DummyLogger implements LoggerInterface
{
public function emergency($message, array $context = [])
{
}
public function alert($message, array $context = [])
{
}
public function critical($message, array $context = [])
{
}
public function error($message, array $context = [])
{
}
public function warning($message, array $context = [])
{
}
public function notice($message, array $context = [])
{
}
public function info($message, array $context = [])
{
}
public function debug($message, array $context = [])
{
}
public function log($level, $message, array $context = [])
{
}
}

class PsrLoggerModule extends AbstractModule
{
protected function configure()
{
$this->bind('Psr\Log\LoggerInterface')->to(__NAMESPACE__ . '\DummyLogger');
}
}

class PsrLoggerInjectTest extends \PHPUnit_Framework_TestCase
{
public function testInjectTrait()
Expand Down
10 changes: 0 additions & 10 deletions tests/Inject/ResourceInjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@
use BEAR\Sunday\Module\Resource\ResourceModule;
use Ray\Di\Injector;

class ResourceInjectApplication
{
use ResourceInject;

public function returnDependency()
{
return $this->resource;
}
}

class ResourceInjectTest extends \PHPUnit_Framework_TestCase
{
public function testInjectTrait()
Expand Down
4 changes: 4 additions & 0 deletions tests/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

require_once __DIR__ . '/Fake/Provide/Transfer/header.php';
require_once __DIR__ . '/Fake/Provide/Transfer/http_response_code.php';

0 comments on commit 2d6a47a

Please sign in to comment.