phpcs and docs
This commit is contained in:
parent
074ca1ee4b
commit
5ee2a60fc1
19 changed files with 230 additions and 192 deletions
25
ruleset.xml
25
ruleset.xml
|
|
@ -3,6 +3,12 @@
|
|||
<description>Yii addon coding standards</description>
|
||||
|
||||
<file>./src</file>
|
||||
<file>./tests</file>
|
||||
|
||||
<exclude-pattern>*/_output/*</exclude-pattern>
|
||||
<exclude-pattern>*/_data/*</exclude-pattern>
|
||||
<exclude-pattern>**.*.css</exclude-pattern>
|
||||
<exclude-pattern>**.*.js</exclude-pattern>
|
||||
|
||||
<arg name="colors"/>
|
||||
|
||||
|
|
@ -14,12 +20,26 @@
|
|||
|
||||
<rule ref="Squiz.Classes.ValidClassName.NotCamelCaps">
|
||||
<exclude-pattern>*/tests/*</exclude-pattern>
|
||||
<exclude-pattern>*/migrations/*</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter.Found">
|
||||
<exclude-pattern>*/tests/*</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
|
||||
<exclude-pattern>*/tests/*</exclude-pattern>
|
||||
<exclude-pattern>*/migrations/*</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="PEAR.Commenting.FunctionComment.MissingParamTag">
|
||||
<exclude-pattern>*/tests/*</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="PSR2.Methods.MethodDeclaration.Underscore">
|
||||
<exclude-pattern>*/tests/*</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="PEAR.Commenting.FunctionComment.Missing">
|
||||
<exclude-pattern>*/tests/*</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="Generic.Commenting.Todo.CommentFound">
|
||||
|
|
@ -67,6 +87,7 @@
|
|||
|
||||
<rule ref="PEAR.Commenting">
|
||||
<exclude name="PEAR.Commenting.FileComment"/>
|
||||
<exclude name="PEAR.Commenting.ClassComment.InvalidPackage"/>
|
||||
</rule>
|
||||
|
||||
<rule ref="PEAR.Commenting.FileComment.MissingCategoryTag">
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class ActiveQuery extends \yii\db\ActiveQuery
|
|||
/**
|
||||
* Overrides the Yii method to return an ActiveRecordCollection instead of an array
|
||||
*
|
||||
* @param mixed $db
|
||||
* @param mixed $db The DB connection used to create the DB command.
|
||||
*
|
||||
* @return ActiveRecordCollection
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -61,10 +61,11 @@ class PageMin extends \yii\base\ActionFilter
|
|||
*/
|
||||
public function minifyHtml( $input )
|
||||
{
|
||||
if(trim($input) === "") return $input;
|
||||
if(trim($input) === '') { return $input;
|
||||
}
|
||||
$input = preg_replace_callback('#<([^\/\s<>!]+)(?:\s+([^<>]*?)\s*|\s*)(\/?)>#s', function($matches) {
|
||||
return '<'.$matches[1].preg_replace('#([^\s=]+)(\=([\'"]?)(.*?)\3)?(\s+|$)#s', ' $1$2', $matches[2]).$matches[3].'>';
|
||||
}, str_replace("\r", "", $input));
|
||||
}, str_replace("\r", '', $input));
|
||||
if(strpos($input, ' style=') !== false) {
|
||||
$input = preg_replace_callback('#<([^<]+?)\s+style=([\'"])(.*?)\2(?=[\/\s>])#s', function($matches) {
|
||||
return '<'.$matches[1].' style='.$matches[2].$this->minifyCss($matches[3]).$matches[2];
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ use yiiaddon\helpers\Enum;
|
|||
*/
|
||||
class ArrayHelper extends \yii\helpers\ArrayHelper
|
||||
{
|
||||
|
||||
/**
|
||||
* Creates a array of numbers
|
||||
*
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class ArrayObject extends \ArrayObject
|
|||
/**
|
||||
* Test that the ArrayObject contains an item
|
||||
*
|
||||
* @param $item The item to test
|
||||
* @param mixed $item The item to test
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
|
@ -197,10 +197,9 @@ class ArrayObject extends \ArrayObject
|
|||
} else {
|
||||
$value = Html::tag('span', $value, $valueOptions);
|
||||
}
|
||||
$table .= "\t\t<th>" . Html::tag( 'span', $key, $keyOptions ) . "</th>" .
|
||||
"<td>" . $value . "</td>\n\t</tr>\n";
|
||||
$table .= "\t\t<th>".Html::tag('span', $key, $keyOptions).'</th>'.'<td>'.$value."</td>\n\t</tr>\n";
|
||||
}
|
||||
$table .= "</table>";
|
||||
$table .= '</table>';
|
||||
return $table;
|
||||
}
|
||||
if (!isset($array[0]) || !is_array($array[0])) {
|
||||
|
|
@ -224,7 +223,7 @@ class ArrayObject extends \ArrayObject
|
|||
// Recursive mode
|
||||
$table .= "\n".static::array2table($cell, true, true)."\n";
|
||||
} else {
|
||||
if ( !is_null( $cell ) && is_bool( $cell ) ) {
|
||||
if ($cell !== null && is_bool($cell)) {
|
||||
$val = $cell ? 'true' : 'false';
|
||||
$type = 'boolean';
|
||||
} else {
|
||||
|
|
@ -244,4 +243,5 @@ class ArrayObject extends \ArrayObject
|
|||
$table .= '</table>';
|
||||
return $table;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,15 +72,15 @@ class Dumper
|
|||
$prop = '';
|
||||
|
||||
if ($propertie->isPublic()) {
|
||||
$prop .= "public";
|
||||
$prop .= 'public';
|
||||
} elseif ($propertie->isPrivate()) {
|
||||
$prop .= "private";
|
||||
$prop .= 'private';
|
||||
} elseif ($propertie->isProtected()) {
|
||||
$prop .= "protected";
|
||||
$prop .= 'protected';
|
||||
}
|
||||
|
||||
if ($propertie->isStatic()) {
|
||||
$prop .= " static";
|
||||
$prop .= ' static';
|
||||
}
|
||||
|
||||
$prop .= " \${$propertie->name}";
|
||||
|
|
@ -93,16 +93,16 @@ class Dumper
|
|||
$prop = '';
|
||||
|
||||
if ($method->isPublic()) {
|
||||
$prop .= "public";
|
||||
$prop .= 'public';
|
||||
} elseif ($method->isPrivate()) {
|
||||
$prop .= "private";
|
||||
$prop .= 'private';
|
||||
} elseif ($method->isProtected()) {
|
||||
$prop .= "protected";
|
||||
$prop .= 'protected';
|
||||
}
|
||||
|
||||
$prop .= " {$method->name}( ";
|
||||
|
||||
$params = "";
|
||||
$params = '';
|
||||
foreach ($method->getParameters() as $parameter) {
|
||||
$params .= "\${$parameter->name}";
|
||||
|
||||
|
|
@ -110,28 +110,28 @@ class Dumper
|
|||
$value = $parameter->getDefaultValue();
|
||||
|
||||
if (is_array($value)) {
|
||||
$value = "[]";
|
||||
$value = '[]';
|
||||
} elseif (is_bool($value)) {
|
||||
$value = $value ? "true" : "false";
|
||||
$value = $value ? 'true' : 'false';
|
||||
}
|
||||
|
||||
$params .= "= {$value}";
|
||||
|
||||
// self::dDump( $parameter->getDefaultValue() );
|
||||
}
|
||||
$params .= ", ";
|
||||
$params .= ', ';
|
||||
}
|
||||
|
||||
$params = rtrim( $params, ", " );
|
||||
$params = rtrim($params, ', ');
|
||||
$prop .= "{$params} )";
|
||||
|
||||
// $prop .= " : {$method->getReturnType()}";
|
||||
|
||||
$dataArray['methords'][$prop] = [
|
||||
"file" => $method->getFileName(),
|
||||
"line" => $method->getStartLine(),
|
||||
'file' => $method->getFileName(),
|
||||
'line' => $method->getStartLine(),
|
||||
'fileLine' => "{$method->getFileName()}:{$method->getStartLine()}",
|
||||
"doc" => $method->getDocComment()
|
||||
'doc' => $method->getDocComment()
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -146,4 +146,5 @@ class Dumper
|
|||
self::dumpInfo($var);
|
||||
die;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class Enum extends \yii\base\Object
|
|||
*/
|
||||
public static function getType( $var )
|
||||
{
|
||||
if (is_null($var)) {
|
||||
if ($var === null) {
|
||||
return self::TYPE_NULL;
|
||||
}
|
||||
|
||||
|
|
@ -127,4 +127,5 @@ class Enum extends \yii\base\Object
|
|||
$bytes /= pow(1024, $pow);
|
||||
return round($bytes, $precision).' '.$units[$pow];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,6 @@ class RedirectRule extends \yii\web\UrlRule
|
|||
|
||||
parent::parseRequest($manager, $request);
|
||||
Yii::$app->end();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ namespace yiiaddon\tests\_data;
|
|||
*/
|
||||
class ModelOne extends \yii\base\Model
|
||||
{
|
||||
|
||||
/**
|
||||
* The first test proprety
|
||||
*
|
||||
|
|
@ -31,4 +32,5 @@ class ModelOne extends \yii\base\Model
|
|||
[ [ 'propOne' ], 'string' ]
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,11 @@ use yiiaddon\tests\_data\ActiveModel;
|
|||
class ActiveRecordCest
|
||||
{
|
||||
|
||||
/**
|
||||
* The instace of ActiveModel that we will be using in the tests
|
||||
*
|
||||
* @var ActiveModel
|
||||
*/
|
||||
public $model;
|
||||
|
||||
public function _before( UnitTester $I )
|
||||
|
|
|
|||
|
|
@ -16,6 +16,11 @@ use yiiaddon\tests\_data\ActiveModel;
|
|||
class ActiveRecordCollectionCest
|
||||
{
|
||||
|
||||
/**
|
||||
* The model collection built before every test
|
||||
*
|
||||
* @var ActiveRecordCollection
|
||||
*/
|
||||
public $model;
|
||||
|
||||
public function _before( UnitTester $I )
|
||||
|
|
|
|||
|
|
@ -15,8 +15,6 @@ use yiiaddon\tests\_data\ModelOne;
|
|||
class ArrayHelperCest
|
||||
{
|
||||
|
||||
|
||||
|
||||
public function _before( UnitTester $I )
|
||||
{
|
||||
}
|
||||
|
|
@ -47,7 +45,7 @@ class ArrayHelperCest
|
|||
{
|
||||
$model = new ModelOne;
|
||||
|
||||
$model->propOne = "test";
|
||||
$model->propOne = 'test';
|
||||
|
||||
$data = ArrayHelper::parseAttribute($model, 'propOne');
|
||||
|
||||
|
|
@ -63,11 +61,12 @@ class ArrayHelperCest
|
|||
{
|
||||
$model = new ModelOne;
|
||||
|
||||
$model->propOne = "test";
|
||||
$model->propOne = 'test';
|
||||
try {
|
||||
$data = ArrayHelper::parseAttribute($model, 'not_a_prop');
|
||||
$I->fail('Not exseption thrown');
|
||||
} catch (\yii\base\UnknownPropertyException $e) {
|
||||
$I->assertEquals($e->getMessage(), 'Getting unknown property: yiiaddon\tests\_data\ModelOne::not_a_prop');
|
||||
} catch (\Exception $e) {
|
||||
$I->fail('\yii\base\UnknownPropertyException should have been thorwn');
|
||||
}
|
||||
|
|
@ -77,13 +76,15 @@ class ArrayHelperCest
|
|||
{
|
||||
$model = new ModelOne;
|
||||
|
||||
$model->propOne = "test";
|
||||
$model->propOne = 'test';
|
||||
try {
|
||||
$data = ArrayHelper::parseAttribute($model, '');
|
||||
$I->fail('Not exseption thrown');
|
||||
} catch (\yii\base\InvalidConfigException $e) {
|
||||
$I->assertEquals($e->getMessage(), 'The column must be specified in the format of "attribute", "attribute:format" or "attribute:format:label"');
|
||||
} catch (\Exception $e) {
|
||||
$I->fail('\yii\base\InvalidConfigException should have been thorwn');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class ArrayObjectCest
|
|||
|
||||
public function testArrayAsProps( UnitTester $I )
|
||||
{
|
||||
$I->assertEquals( $this->arrayObject->key_one, "Value One" );
|
||||
$I->assertEquals($this->arrayObject->key_one, 'Value One');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -41,8 +41,8 @@ class ArrayObjectCest
|
|||
*/
|
||||
public function testArrayContains( UnitTester $I )
|
||||
{
|
||||
$I->assertTrue( $this->arrayObject->contains( "Value One" ) );
|
||||
$I->assertFalse( $this->arrayObject->contains( "Not in array" ) );
|
||||
$I->assertTrue($this->arrayObject->contains('Value One'));
|
||||
$I->assertFalse($this->arrayObject->contains('Not in array'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -48,4 +48,5 @@ class EnumCest
|
|||
$I->assertEquals($type, Enum::getType($var));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@
|
|||
* @since v0.1
|
||||
*/
|
||||
|
||||
require __DIR__ . "/../../vendor/autoload.php";
|
||||
require __DIR__ . "/../../vendor/yiisoft/yii2/Yii.php";
|
||||
require __DIR__.'/../../vendor/autoload.php';
|
||||
require __DIR__.'/../../vendor/yiisoft/yii2/Yii.php';
|
||||
|
||||
$config = [
|
||||
'id' => 'Yii Helpers Tests',
|
||||
|
|
|
|||
Loading…
Reference in a new issue