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