";
- foreach ( $row as $cell ) {
+ foreach ($row as $cell) {
$table .= '| ';
// Cast objects
- if ( is_object( $cell ) ) {
- $cell = (array)$cell;
+ if (is_object($cell)) {
+ $cell = (array) $cell;
}
- if ( $recursive === true && is_array( $cell ) && !empty( $cell ) ) {
+ if ($recursive === true && is_array($cell) && !empty($cell)) {
// Recursive mode
- $table .= "\n" . static::array2table( $cell, true, true ) . "\n";
+ $table .= "\n".static::array2table($cell, true, true)."\n";
} else {
- if ( !is_null( $cell ) && is_bool( $cell ) ) {
- $val = $cell ? 'true' : 'false';
+ if ($cell !== null && is_bool($cell)) {
+ $val = $cell ? 'true' : 'false';
$type = 'boolean';
} else {
- $chk = ( strlen( $cell ) > 0 );
- $type = $chk ? Enum::getType( $cell ) : 'null';
- $val = $chk ? htmlspecialchars( (string)$cell ) : $null;
+ $chk = ( strlen($cell) > 0 );
+ $type = $chk ? Enum::getType($cell) : 'null';
+ $val = $chk ? htmlspecialchars((string) $cell) : $null;
}
- if ( $typeHint ) {
+ if ($typeHint) {
$valueOptions['title'] = $type;
}
- $table .= Html::tag( 'span', $val, $valueOptions );
+ $table .= Html::tag('span', $val, $valueOptions);
}
$table .= ' | ';
}
@@ -244,4 +243,5 @@ class ArrayObject extends \ArrayObject
$table .= '';
return $table;
}
+
}
diff --git a/src/helpers/Dumper.php b/src/helpers/Dumper.php
index 39f4f87..7c2d2dd 100644
--- a/src/helpers/Dumper.php
+++ b/src/helpers/Dumper.php
@@ -38,22 +38,22 @@ class Dumper
);
public static function dump( $var ) {
- VarDumper::setHandler( function ( $var ) {
+ VarDumper::setHandler(function ( $var ) {
$cloner = new VarCloner();
$dumper = 'cli' === PHP_SAPI ? new CliDumper() : new HtmlDumper();
- $dumper->setStyles( self::$styles );
- $dumper->setDisplayOptions( self::$displayOptions );
+ $dumper->setStyles(self::$styles);
+ $dumper->setDisplayOptions(self::$displayOptions);
- $dumper->dump( $cloner->cloneVar( $var ) );
- } );
+ $dumper->dump($cloner->cloneVar($var));
+ });
- dump( $var );
+ dump($var);
}
public static function dDump( $var )
{
- self::dump( $var );
+ self::dump($var);
die;
}
@@ -61,89 +61,90 @@ class Dumper
{
$dataArray = [];
- $class = new \ReflectionClass( $var );
+ $class = new \ReflectionClass($var);
- $dataArray[ 'name' ] = $class->name;
+ $dataArray['name'] = $class->name;
- $methods = $class->getMethods();
- $dataArray[ 'constants'] = ( array )$class->getConstants();
+ $methods = $class->getMethods();
+ $dataArray['constants'] = ( array ) $class->getConstants();
- foreach ( $class->getProperties() as $propertie ) {
+ foreach ($class->getProperties() as $propertie) {
$prop = '';
- if ( $propertie->isPublic() ) {
- $prop .= "public";
- } elseif ( $propertie->isPrivate() ) {
- $prop .= "private";
- } elseif ( $propertie->isProtected() ) {
- $prop .= "protected";
+ if ($propertie->isPublic()) {
+ $prop .= 'public';
+ } elseif ($propertie->isPrivate()) {
+ $prop .= 'private';
+ } elseif ($propertie->isProtected()) {
+ $prop .= 'protected';
}
- if ( $propertie->isStatic() ) {
- $prop .= " static";
+ if ($propertie->isStatic()) {
+ $prop .= ' static';
}
$prop .= " \${$propertie->name}";
- $dataArray[ 'properties' ][] = $prop;
+ $dataArray['properties'][] = $prop;
}
- foreach ( $methods as $method ) {
+ foreach ($methods as $method) {
$prop = '';
- if ( $method->isPublic() ) {
- $prop .= "public";
- } elseif ( $method->isPrivate() ) {
- $prop .= "private";
- } elseif ( $method->isProtected() ) {
- $prop .= "protected";
+ if ($method->isPublic()) {
+ $prop .= 'public';
+ } elseif ($method->isPrivate()) {
+ $prop .= 'private';
+ } elseif ($method->isProtected()) {
+ $prop .= 'protected';
}
$prop .= " {$method->name}( ";
- $params = "";
- foreach ( $method->getParameters() as $parameter ) {
+ $params = '';
+ foreach ($method->getParameters() as $parameter) {
$params .= "\${$parameter->name}";
- if ( $parameter->isDefaultValueAvailable() ) {
+ if ($parameter->isDefaultValueAvailable()) {
$value = $parameter->getDefaultValue();
- if ( is_array( $value ) ) {
- $value = "[]";
- } elseif ( is_bool( $value ) ) {
- $value = $value ? "true" : "false";
+ if (is_array($value)) {
+ $value = '[]';
+ } elseif (is_bool($value)) {
+ $value = $value ? 'true' : 'false';
}
$params .= "= {$value}";
// self::dDump( $parameter->getDefaultValue() );
}
- $params .= ", ";
+ $params .= ', ';
}
- $params = rtrim( $params, ", " );
- $prop .= "{$params} )";
+ $params = rtrim($params, ', ');
+ $prop .= "{$params} )";
// $prop .= " : {$method->getReturnType()}";
- $dataArray[ 'methords' ][ $prop ] = [
- "file" => $method->getFileName(),
- "line" => $method->getStartLine(),
+ $dataArray['methords'][$prop] = [
+ 'file' => $method->getFileName(),
+ 'line' => $method->getStartLine(),
'fileLine' => "{$method->getFileName()}:{$method->getStartLine()}",
- "doc" => $method->getDocComment()
+ 'doc' => $method->getDocComment()
];
}
- sort( $dataArray[ 'properties' ] );
- ksort( $dataArray[ 'constants' ] );
- ksort( $dataArray[ 'methords' ] );
- self::dDump( $dataArray );
+ sort($dataArray['properties']);
+ ksort($dataArray['constants']);
+ ksort($dataArray['methords']);
+ self::dDump($dataArray);
}
public static function dDumpInfo( $var )
{
- self::dumpInfo( $var );
+ self::dumpInfo($var);
die;
}
+
}
diff --git a/src/helpers/Enum.php b/src/helpers/Enum.php
index 20646ec..1a1b40b 100644
--- a/src/helpers/Enum.php
+++ b/src/helpers/Enum.php
@@ -48,34 +48,34 @@ class Enum extends \yii\base\Object
*/
public static function getType( $var )
{
- if (is_null($var)) {
+ if ($var === null) {
return self::TYPE_NULL;
}
- if (is_array( $var )) {
+ if (is_array($var)) {
return self::TYPE_ARRAY;
}
- if (is_bool( $var )) {
+ if (is_bool($var)) {
return self::TYPE_BOOL;
}
- if (is_float( $var )
+ if (is_float($var)
|| (!is_object($var) &&
- is_numeric( str_replace( ',', '', $var ) ) && strpos( $var, '.' ) > 0 && is_float( ( float )str_replace( ',', '', $var ) ))
+ is_numeric(str_replace(',', '', $var)) && strpos($var, '.') > 0 && is_float(( float ) str_replace(',', '', $var)))
) {
return self::TYPE_FLOAT;
}
- if (is_int( $var ) || ( is_numeric( $var ) && is_int( ( int )$var ) )) {
+ if (is_int($var) || ( is_numeric($var) && is_int(( int ) $var) )) {
return self::TYPE_INT;
}
- if (is_scalar( $var ) && strtotime( $var ) !== false) {
+ if (is_scalar($var) && strtotime($var) !== false) {
return self::TYPE_DATETIME;
}
- if (is_scalar( $var )) {
+ if (is_scalar($var)) {
return self::TYPE_STRING;
}
@@ -99,7 +99,7 @@ class Enum extends \yii\base\Object
*/
public static function isEmpty( $var )
{
- return !isset( $var ) ? true : ( is_array( $var ) ? empty( $var ) : ( $var === null || $var === '' ) );
+ return !isset($var) ? true : ( is_array($var) ? empty($var) : ( $var === null || $var === '' ) );
}
/**
@@ -120,11 +120,12 @@ class Enum extends \yii\base\Object
*/
public static function formatBytes( $bytes, $precision = 2 )
{
- $units = [ 'B', 'KB', 'MB', 'GB', 'TB' ];
- $bytes = max( $bytes, 0 );
- $pow = floor( ( $bytes ? log( $bytes ) : 0 ) / log( 1024 ) );
- $pow = min( $pow, count( $units ) - 1 );
- $bytes /= pow( 1024, $pow );
- return round( $bytes, $precision ) . ' ' . $units[$pow];
+ $units = [ 'B', 'KB', 'MB', 'GB', 'TB' ];
+ $bytes = max($bytes, 0);
+ $pow = floor(( $bytes ? log($bytes) : 0 ) / log(1024));
+ $pow = min($pow, count($units) - 1);
+ $bytes /= pow(1024, $pow);
+ return round($bytes, $precision).' '.$units[$pow];
}
+
}
diff --git a/src/web/RedirectRule.php b/src/web/RedirectRule.php
index d626332..5c94a3a 100644
--- a/src/web/RedirectRule.php
+++ b/src/web/RedirectRule.php
@@ -31,7 +31,7 @@ use yii\helpers\Url;
*/
class RedirectRule extends \yii\web\UrlRule
{
- public $permanents = [];
+ public $permanents = [];
public $temporaries = [];
@@ -55,14 +55,13 @@ class RedirectRule extends \yii\web\UrlRule
if(in_array($pathInfo, $this->permanents)) {
$request->setPathInfo($this->name);
Yii::$app->response->redirect($this->name, 301);
- } else if(in_array($pathInfo, $this->temporaries)) {
+ } elseif(in_array($pathInfo, $this->temporaries)) {
$request->setPathInfo($this->name);
Yii::$app->response->redirect($this->name, 302);
}
parent::parseRequest($manager, $request);
Yii::$app->end();
-
}
}
diff --git a/src/web/View.php b/src/web/View.php
index 807d3d8..c86b793 100644
--- a/src/web/View.php
+++ b/src/web/View.php
@@ -202,7 +202,7 @@ class View extends \yii\web\View
$this->registerGoogleAnalytics();
}
- return '' . $this->title . '' . parent::renderHeadHtml();
+ return ''.$this->title.''.parent::renderHeadHtml();
}
/**
@@ -212,7 +212,7 @@ class View extends \yii\web\View
*/
public function registerGoogleAnalytics()
{
- $js = "(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','$this->googleAnalyticsFile','$this->googleAnalyticsVar');";
+ $js = "(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','$this->googleAnalyticsFile','$this->googleAnalyticsVar');";
$js .= "$this->googleAnalyticsVar('create', '$this->googleAnalyticsCode', 'auto');";
$js .= "$this->googleAnalyticsVar('send', 'pageview');";
diff --git a/tests/_data/ModelOne.php b/tests/_data/ModelOne.php
index 31f0ec8..e71c066 100644
--- a/tests/_data/ModelOne.php
+++ b/tests/_data/ModelOne.php
@@ -12,7 +12,8 @@ namespace yiiaddon\tests\_data;
* @since v0.1
*/
class ModelOne extends \yii\base\Model
-{
+{
+
/**
* The first test proprety
*
@@ -31,4 +32,5 @@ class ModelOne extends \yii\base\Model
[ [ 'propOne' ], 'string' ]
];
}
+
}
diff --git a/tests/unit/ActiveRecordCest.php b/tests/unit/ActiveRecordCest.php
index c88a7fc..8befb3b 100644
--- a/tests/unit/ActiveRecordCest.php
+++ b/tests/unit/ActiveRecordCest.php
@@ -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 )
diff --git a/tests/unit/ActiveRecordCollectionCest.php b/tests/unit/ActiveRecordCollectionCest.php
index 108bc55..4358924 100644
--- a/tests/unit/ActiveRecordCollectionCest.php
+++ b/tests/unit/ActiveRecordCollectionCest.php
@@ -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 )
diff --git a/tests/unit/ArrayHelperCest.php b/tests/unit/ArrayHelperCest.php
index d150a57..a9d50ef 100644
--- a/tests/unit/ArrayHelperCest.php
+++ b/tests/unit/ArrayHelperCest.php
@@ -15,8 +15,6 @@ use yiiaddon\tests\_data\ModelOne;
class ArrayHelperCest
{
-
-
public function _before( UnitTester $I )
{
}
@@ -27,49 +25,50 @@ class ArrayHelperCest
public function testNumberArray( UnitTester $I )
{
- $array = ArrayHelper::numberArray( 10, 2, 2 );
+ $array = ArrayHelper::numberArray(10, 2, 2);
- $I->assertEquals( $array[ 2 ], 2 );
- $I->assertFalse( isset( $array[ 3 ] ) );
- $I->assertEquals( $array[ 4 ], 4 );
+ $I->assertEquals($array[2], 2);
+ $I->assertFalse(isset($array[3]));
+ $I->assertEquals($array[4], 4);
}
public function testNumberArrayWithStep( UnitTester $I )
{
- $array = ArrayHelper::numberArray( 10 );
+ $array = ArrayHelper::numberArray(10);
- $I->assertEquals( $array[ 0 ], 0 );
- $I->assertEquals( $array[ 10 ], 10 );
- $I->assertFalse( isset( $array[ 11 ] ) );
+ $I->assertEquals($array[0], 0);
+ $I->assertEquals($array[10], 10);
+ $I->assertFalse(isset($array[11]));
}
public function testParseAttribute( UnitTester $I )
{
$model = new ModelOne;
- $model->propOne = "test";
+ $model->propOne = 'test';
- $data = ArrayHelper::parseAttribute( $model, 'propOne' );
+ $data = ArrayHelper::parseAttribute($model, 'propOne');
- $I->assertEquals( $data->format, 'text' );
+ $I->assertEquals($data->format, 'text');
- $I->assertEquals( $data->lable, 'Prop One' );
+ $I->assertEquals($data->lable, 'Prop One');
- $I->assertEquals( $data->value, 'test' );
- $I->assertEquals( $data->raw, 'test' );
+ $I->assertEquals($data->value, 'test');
+ $I->assertEquals($data->raw, 'test');
}
public function testErrorWithParseAttribute( UnitTester $I )
{
$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 ) {
- } catch ( \Exception $e ) {
- $I->fail( '\yii\base\UnknownPropertyException should have been thorwn' );
+ $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 ) {
- } catch ( \Exception $e ) {
- $I->fail( '\yii\base\InvalidConfigException should have been thorwn' );
+ $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');
}
}
+
}
diff --git a/tests/unit/ArrayObjectCest.php b/tests/unit/ArrayObjectCest.php
index 7298e1b..cb7963c 100644
--- a/tests/unit/ArrayObjectCest.php
+++ b/tests/unit/ArrayObjectCest.php
@@ -22,7 +22,7 @@ class ArrayObjectCest
public function _before( UnitTester $I )
{
- $this->arrayObject = new ArrayObject( $this->array );
+ $this->arrayObject = new ArrayObject($this->array);
}
public function _after( UnitTester $I )
@@ -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'));
}
/**
@@ -54,14 +54,14 @@ class ArrayObjectCest
{
$table = $this->arrayObject->toTable();
- $I->assertContains( '', $table );
- $I->assertContains( 'Value One', $table );
+ $I->assertContains('', $table);
+ $I->assertContains('Value One', $table);
}
public function testRandomValue( UnitTester $I )
{
- for( $i = 0; $i < 5; $i++ ) {
- $I->assertContains( $this->arrayObject->randomValue(), $this->array );
+ for($i = 0; $i < 5; $i++) {
+ $I->assertContains($this->arrayObject->randomValue(), $this->array);
}
}
diff --git a/tests/unit/EnumCest.php b/tests/unit/EnumCest.php
index 7297bdf..c3a6555 100644
--- a/tests/unit/EnumCest.php
+++ b/tests/unit/EnumCest.php
@@ -24,8 +24,8 @@ class EnumCest
public function testNumberArray( UnitTester $I )
{
- $I->assertEquals( Enum::formatBytes( 28434322.25 ), '27.12 MB' );
- $I->assertEquals( Enum::formatBytes( 17328347842.25, 3 ), '16.138 GB' );
+ $I->assertEquals(Enum::formatBytes(28434322.25), '27.12 MB');
+ $I->assertEquals(Enum::formatBytes(17328347842.25, 3), '16.138 GB');
}
/**
@@ -44,8 +44,9 @@ class EnumCest
'unknown' => new StdClass()
];
- foreach ( $array as $type => $var ) {
- $I->assertEquals( $type, Enum::getType( $var ) );
+ foreach ($array as $type => $var) {
+ $I->assertEquals($type, Enum::getType($var));
}
}
+
}
diff --git a/tests/unit/_bootstrap.php b/tests/unit/_bootstrap.php
index ab1cda6..672480c 100644
--- a/tests/unit/_bootstrap.php
+++ b/tests/unit/_bootstrap.php
@@ -10,12 +10,12 @@
* @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',
- 'basePath' => dirname( __DIR__ )
+ 'basePath' => dirname(__DIR__)
];
-( new yii\web\Application( $config ) );
+( new yii\web\Application($config) );