diff --git a/apps/bootstrap/index.php b/apps/bootstrap/index.php index dec6e35..cf87d81 100644 --- a/apps/bootstrap/index.php +++ b/apps/bootstrap/index.php @@ -1,5 +1,5 @@ params['breadcrumbs'][] = $this->title; ?>

title); ?>

-session->hasFlash('contactFormSubmitted')): ?> +session->hasFlash('contactFormSubmitted')): ?>
Thank you for contacting us. We will respond to you as soon as possible.
diff --git a/docs/guide/performance.md b/docs/guide/performance.md index 9a871dc..35efa67 100644 --- a/docs/guide/performance.md +++ b/docs/guide/performance.md @@ -162,7 +162,7 @@ class PostController extends Controller In the view you should access fields of each invidual record from `$posts` as array: ```php -foreach($posts as $post) { +foreach ($posts as $post) { echo $post['title']."
"; } ``` diff --git a/tests/unit/framework/base/DictionaryTest.php b/tests/unit/framework/base/DictionaryTest.php index 9e55547..40cabbb 100644 --- a/tests/unit/framework/base/DictionaryTest.php +++ b/tests/unit/framework/base/DictionaryTest.php @@ -15,52 +15,54 @@ class DictionaryTest extends \yiiunit\TestCase * @var \yii\base\Dictionary */ protected $dictionary; - protected $item1,$item2,$item3; + protected $item1; + protected $item2; + protected $item3; public function setUp() { - $this->dictionary=new Dictionary; - $this->item1=new MapItem; - $this->item2=new MapItem; - $this->item3=new MapItem; - $this->dictionary->add('key1',$this->item1); - $this->dictionary->add('key2',$this->item2); + $this->dictionary = new Dictionary; + $this->item1 = new MapItem; + $this->item2 = new MapItem; + $this->item3 = new MapItem; + $this->dictionary->add('key1', $this->item1); + $this->dictionary->add('key2', $this->item2); } public function tearDown() { - $this->dictionary=null; - $this->item1=null; - $this->item2=null; - $this->item3=null; + $this->dictionary = null; + $this->item1 = null; + $this->item2 = null; + $this->item3 = null; } public function testConstruct() { - $a=array(1,2,'key3'=>3); - $dictionary=new Dictionary($a); - $this->assertEquals(3,$dictionary->getCount()); + $a = array(1, 2, 'key3' => 3); + $dictionary = new Dictionary($a); + $this->assertEquals(3, $dictionary->getCount()); $dictionary2=new Dictionary($this->dictionary); - $this->assertEquals(2,$dictionary2->getCount()); + $this->assertEquals(2, $dictionary2->getCount()); } public function testGetCount() { - $this->assertEquals(2,$this->dictionary->getCount()); + $this->assertEquals(2, $this->dictionary->getCount()); } public function testGetKeys() { - $keys=$this->dictionary->getKeys(); - $this->assertEquals(2,count($keys)); - $this->assertEquals('key1',$keys[0]); - $this->assertEquals('key2',$keys[1]); + $keys = $this->dictionary->getKeys(); + $this->assertEquals(2, count($keys)); + $this->assertEquals('key1', $keys[0]); + $this->assertEquals('key2', $keys[1]); } public function testAdd() { - $this->dictionary->add('key3',$this->item3); - $this->assertEquals(3,$this->dictionary->getCount()); + $this->dictionary->add('key3', $this->item3); + $this->assertEquals(3, $this->dictionary->getCount()); $this->assertTrue($this->dictionary->has('key3')); $this->dictionary[] = 'test'; @@ -69,21 +71,21 @@ class DictionaryTest extends \yiiunit\TestCase public function testRemove() { $this->dictionary->remove('key1'); - $this->assertEquals(1,$this->dictionary->getCount()); + $this->assertEquals(1, $this->dictionary->getCount()); $this->assertTrue(!$this->dictionary->has('key1')); - $this->assertTrue($this->dictionary->remove('unknown key')===null); + $this->assertTrue($this->dictionary->remove('unknown key') === null); } public function testRemoveAll() { - $this->dictionary->add('key3',$this->item3); + $this->dictionary->add('key3', $this->item3); $this->dictionary->removeAll(); - $this->assertEquals(0,$this->dictionary->getCount()); + $this->assertEquals(0, $this->dictionary->getCount()); $this->assertTrue(!$this->dictionary->has('key1') && !$this->dictionary->has('key2')); - $this->dictionary->add('key3',$this->item3); + $this->dictionary->add('key3', $this->item3); $this->dictionary->removeAll(true); - $this->assertEquals(0,$this->dictionary->getCount()); + $this->assertEquals(0, $this->dictionary->getCount()); $this->assertTrue(!$this->dictionary->has('key1') && !$this->dictionary->has('key2')); } @@ -96,7 +98,7 @@ class DictionaryTest extends \yiiunit\TestCase public function testFromArray() { - $array=array('key3'=>$this->item3,'key4'=>$this->item1); + $array = array('key3' => $this->item3, 'key4' => $this->item1); $this->dictionary->copyFrom($array); $this->assertEquals(2, $this->dictionary->getCount()); @@ -109,21 +111,21 @@ class DictionaryTest extends \yiiunit\TestCase public function testMergeWith() { - $a=array('a'=>'v1','v2',array('2'),'c'=>array('3','c'=>'a')); - $b=array('v22','a'=>'v11',array('2'),'c'=>array('c'=>'3','a')); - $c=array('a'=>'v11','v2',array('2'),'c'=>array('3','c'=>'3','a'),'v22',array('2')); - $dictionary=new Dictionary($a); - $dictionary2=new Dictionary($b); + $a = array('a' => 'v1', 'v2', array('2'), 'c' => array('3','c' => 'a')); + $b = array('v22', 'a' => 'v11', array('2'), 'c' => array('c' => '3','a')); + $c = array('a' => 'v11', 'v2', array('2'), 'c' => array('3', 'c' => '3', 'a'), 'v22', array('2')); + $dictionary = new Dictionary($a); + $dictionary2 = new Dictionary($b); $dictionary->mergeWith($dictionary2); - $this->assertTrue($dictionary->toArray()===$c); + $this->assertTrue($dictionary->toArray() === $c); - $array=array('key2'=>$this->item1,'key3'=>$this->item3); - $this->dictionary->mergeWith($array,false); - $this->assertEquals(3,$this->dictionary->getCount()); - $this->assertEquals($this->item1,$this->dictionary['key2']); - $this->assertEquals($this->item3,$this->dictionary['key3']); + $array = array('key2' => $this->item1, 'key3' => $this->item3); + $this->dictionary->mergeWith($array, false); + $this->assertEquals(3, $this->dictionary->getCount()); + $this->assertEquals($this->item1, $this->dictionary['key2']); + $this->assertEquals($this->item3, $this->dictionary['key3']); $this->setExpectedException('yii\base\InvalidParamException'); - $this->dictionary->mergeWith($this,false); + $this->dictionary->mergeWith($this, false); } public function testRecursiveMergeWithTraversable(){ @@ -135,7 +137,7 @@ class DictionaryTest extends \yiiunit\TestCase 'k4' => $this->item3, )) )); - $dictionary->mergeWith($obj,true); + $dictionary->mergeWith($obj, true); $this->assertEquals(3, $dictionary->getCount()); $this->assertEquals($this->item1, $dictionary['k1']); @@ -145,23 +147,23 @@ class DictionaryTest extends \yiiunit\TestCase public function testArrayRead() { - $this->assertEquals($this->item1,$this->dictionary['key1']); - $this->assertEquals($this->item2,$this->dictionary['key2']); - $this->assertEquals(null,$this->dictionary['key3']); + $this->assertEquals($this->item1, $this->dictionary['key1']); + $this->assertEquals($this->item2, $this->dictionary['key2']); + $this->assertEquals(null, $this->dictionary['key3']); } public function testArrayWrite() { - $this->dictionary['key3']=$this->item3; - $this->assertEquals(3,$this->dictionary->getCount()); - $this->assertEquals($this->item3,$this->dictionary['key3']); + $this->dictionary['key3'] = $this->item3; + $this->assertEquals(3, $this->dictionary->getCount()); + $this->assertEquals($this->item3, $this->dictionary['key3']); - $this->dictionary['key1']=$this->item3; - $this->assertEquals(3,$this->dictionary->getCount()); - $this->assertEquals($this->item3,$this->dictionary['key1']); + $this->dictionary['key1'] = $this->item3; + $this->assertEquals(3, $this->dictionary->getCount()); + $this->assertEquals($this->item3, $this->dictionary['key1']); unset($this->dictionary['key2']); - $this->assertEquals(2,$this->dictionary->getCount()); + $this->assertEquals(2, $this->dictionary->getCount()); $this->assertTrue(!$this->dictionary->has('key2')); unset($this->dictionary['unknown key']); @@ -169,22 +171,23 @@ class DictionaryTest extends \yiiunit\TestCase public function testArrayForeach() { - $n=0; - $found=0; - foreach($this->dictionary as $index=>$item) - { + $n = 0; + $found = 0; + foreach ($this->dictionary as $index => $item) { $n++; - if($index==='key1' && $item===$this->item1) + if ($index === 'key1' && $item === $this->item1) { $found++; - if($index==='key2' && $item===$this->item2) + } + if ($index === 'key2' && $item === $this->item2) { $found++; + } } - $this->assertTrue($n==2 && $found==2); + $this->assertTrue($n == 2 && $found == 2); } public function testArrayMisc() { - $this->assertEquals($this->dictionary->Count,count($this->dictionary)); + $this->assertEquals($this->dictionary->Count, count($this->dictionary)); $this->assertTrue(isset($this->dictionary['key1'])); $this->assertFalse(isset($this->dictionary['unknown key'])); } diff --git a/tests/unit/framework/base/ModelTest.php b/tests/unit/framework/base/ModelTest.php index f04e550..cf6f09f 100644 --- a/tests/unit/framework/base/ModelTest.php +++ b/tests/unit/framework/base/ModelTest.php @@ -155,7 +155,7 @@ class ModelTest extends TestCase // iteration $attributes = array(); - foreach($speaker as $key => $attribute) { + foreach ($speaker as $key => $attribute) { $attributes[$key] = $attribute; } $this->assertEquals(array( diff --git a/tests/unit/framework/base/VectorTest.php b/tests/unit/framework/base/VectorTest.php index 5c44d17..b14d5dc 100644 --- a/tests/unit/framework/base/VectorTest.php +++ b/tests/unit/framework/base/VectorTest.php @@ -15,39 +15,41 @@ class VectorTest extends \yiiunit\TestCase * @var Vector */ protected $vector; - protected $item1, $item2, $item3; + protected $item1; + protected $item2; + protected $item3; public function setUp() { - $this->vector=new Vector; - $this->item1=new ListItem; - $this->item2=new ListItem; - $this->item3=new ListItem; + $this->vector = new Vector; + $this->item1 = new ListItem; + $this->item2 = new ListItem; + $this->item3 = new ListItem; $this->vector->add($this->item1); $this->vector->add($this->item2); } public function tearDown() { - $this->vector=null; - $this->item1=null; - $this->item2=null; - $this->item3=null; + $this->vector = null; + $this->item1 = null; + $this->item2 = null; + $this->item3 = null; } public function testConstruct() { - $a=array(1,2,3); - $vector=new Vector($a); - $this->assertEquals(3,$vector->getCount()); - $vector2=new Vector($this->vector); - $this->assertEquals(2,$vector2->getCount()); + $a = array(1, 2, 3); + $vector = new Vector($a); + $this->assertEquals(3, $vector->getCount()); + $vector2 = new Vector($this->vector); + $this->assertEquals(2, $vector2->getCount()); } public function testItemAt() { - $a=array(1, 2, null, 4); - $vector=new Vector($a); + $a = array(1, 2, null, 4); + $vector = new Vector($a); $this->assertEquals(1, $vector->itemAt(0)); $this->assertEquals(2, $vector->itemAt(1)); $this->assertNull($vector->itemAt(2)); @@ -56,37 +58,37 @@ class VectorTest extends \yiiunit\TestCase public function testGetCount() { - $this->assertEquals(2,$this->vector->getCount()); - $this->assertEquals(2,$this->vector->Count); + $this->assertEquals(2, $this->vector->getCount()); + $this->assertEquals(2, $this->vector->Count); } public function testAdd() { $this->vector->add(null); $this->vector->add($this->item3); - $this->assertEquals(4,$this->vector->getCount()); - $this->assertEquals(3,$this->vector->indexOf($this->item3)); + $this->assertEquals(4, $this->vector->getCount()); + $this->assertEquals(3, $this->vector->indexOf($this->item3)); } public function testInsertAt() { - $this->vector->insertAt(0,$this->item3); - $this->assertEquals(3,$this->vector->getCount()); - $this->assertEquals(2,$this->vector->indexOf($this->item2)); - $this->assertEquals(0,$this->vector->indexOf($this->item3)); - $this->assertEquals(1,$this->vector->indexOf($this->item1)); + $this->vector->insertAt(0, $this->item3); + $this->assertEquals(3, $this->vector->getCount()); + $this->assertEquals(2, $this->vector->indexOf($this->item2)); + $this->assertEquals(0, $this->vector->indexOf($this->item3)); + $this->assertEquals(1, $this->vector->indexOf($this->item1)); $this->setExpectedException('yii\base\InvalidParamException'); - $this->vector->insertAt(4,$this->item3); + $this->vector->insertAt(4, $this->item3); } public function testRemove() { $this->vector->remove($this->item1); - $this->assertEquals(1,$this->vector->getCount()); - $this->assertEquals(-1,$this->vector->indexOf($this->item1)); - $this->assertEquals(0,$this->vector->indexOf($this->item2)); + $this->assertEquals(1, $this->vector->getCount()); + $this->assertEquals(-1, $this->vector->indexOf($this->item1)); + $this->assertEquals(0, $this->vector->indexOf($this->item2)); - $this->assertEquals(false,$this->vector->remove($this->item1)); + $this->assertEquals(false, $this->vector->remove($this->item1)); } @@ -94,9 +96,9 @@ class VectorTest extends \yiiunit\TestCase { $this->vector->add($this->item3); $this->vector->removeAt(1); - $this->assertEquals(-1,$this->vector->indexOf($this->item2)); - $this->assertEquals(1,$this->vector->indexOf($this->item3)); - $this->assertEquals(0,$this->vector->indexOf($this->item1)); + $this->assertEquals(-1, $this->vector->indexOf($this->item2)); + $this->assertEquals(1, $this->vector->indexOf($this->item3)); + $this->assertEquals(0, $this->vector->indexOf($this->item1)); $this->setExpectedException('yii\base\InvalidParamException'); $this->vector->removeAt(2); } @@ -105,15 +107,15 @@ class VectorTest extends \yiiunit\TestCase { $this->vector->add($this->item3); $this->vector->removeAll(); - $this->assertEquals(0,$this->vector->getCount()); - $this->assertEquals(-1,$this->vector->indexOf($this->item1)); - $this->assertEquals(-1,$this->vector->indexOf($this->item2)); + $this->assertEquals(0, $this->vector->getCount()); + $this->assertEquals(-1, $this->vector->indexOf($this->item1)); + $this->assertEquals(-1, $this->vector->indexOf($this->item2)); $this->vector->add($this->item3); $this->vector->removeAll(true); - $this->assertEquals(0,$this->vector->getCount()); - $this->assertEquals(-1,$this->vector->indexOf($this->item1)); - $this->assertEquals(-1,$this->vector->indexOf($this->item2)); + $this->assertEquals(0, $this->vector->getCount()); + $this->assertEquals(-1, $this->vector->indexOf($this->item1)); + $this->assertEquals(-1, $this->vector->indexOf($this->item2)); } public function testHas() @@ -125,30 +127,32 @@ class VectorTest extends \yiiunit\TestCase public function testIndexOf() { - $this->assertEquals(0,$this->vector->indexOf($this->item1)); - $this->assertEquals(1,$this->vector->indexOf($this->item2)); - $this->assertEquals(-1,$this->vector->indexOf($this->item3)); + $this->assertEquals(0, $this->vector->indexOf($this->item1)); + $this->assertEquals(1, $this->vector->indexOf($this->item2)); + $this->assertEquals(-1, $this->vector->indexOf($this->item3)); } public function testFromArray() { - $array=array($this->item3,$this->item1); + $array = array($this->item3, $this->item1); $this->vector->copyFrom($array); - $this->assertTrue(count($array)==2 && $this->vector[0]===$this->item3 && $this->vector[1]===$this->item1); + $this->assertTrue(count($array) == 2 && $this->vector[0] === $this->item3 && $this->vector[1] === $this->item1); $this->setExpectedException('yii\base\InvalidParamException'); $this->vector->copyFrom($this); } public function testMergeWith() { - $array=array($this->item3,$this->item1); + $array = array($this->item3, $this->item1); $this->vector->mergeWith($array); - $this->assertTrue($this->vector->getCount()==4 && $this->vector[0]===$this->item1 && $this->vector[3]===$this->item1); + $this->assertTrue($this->vector->getCount() == 4 && $this->vector[0] === $this->item1 && + $this->vector[3] === $this->item1); - $a=array(1); - $vector=new Vector($a); + $a = array(1); + $vector = new Vector($a); $this->vector->mergeWith($vector); - $this->assertTrue($this->vector->getCount()==5 && $this->vector[0]===$this->item1 && $this->vector[3]===$this->item1 && $this->vector[4]===1); + $this->assertTrue($this->vector->getCount() == 5 && $this->vector[0] === $this->item1 && + $this->vector[3] === $this->item1 && $this->vector[4] === 1); $this->setExpectedException('yii\base\InvalidParamException'); $this->vector->mergeWith($this); @@ -156,37 +160,40 @@ class VectorTest extends \yiiunit\TestCase public function testToArray() { - $array=$this->vector->toArray(); - $this->assertTrue(count($array)==2 && $array[0]===$this->item1 && $array[1]===$this->item2); + $array = $this->vector->toArray(); + $this->assertTrue(count($array) == 2 && $array[0] === $this->item1 && $array[1] === $this->item2); } public function testArrayRead() { - $this->assertTrue($this->vector[0]===$this->item1); - $this->assertTrue($this->vector[1]===$this->item2); + $this->assertTrue($this->vector[0] === $this->item1); + $this->assertTrue($this->vector[1] === $this->item2); $this->setExpectedException('yii\base\InvalidParamException'); - $a=$this->vector[2]; + $a = $this->vector[2]; } public function testGetIterator() { - $n=0; - $found=0; - foreach($this->vector as $index=>$item) - { - foreach($this->vector as $a=>$b); // test of iterator + $n = 0; + $found = 0; + foreach ($this->vector as $index => $item) { + foreach ($this->vector as $a => $b) { + // test of iterator + } $n++; - if($index===0 && $item===$this->item1) + if ($index === 0 && $item === $this->item1) { $found++; - if($index===1 && $item===$this->item2) + } + if ($index === 1 && $item === $this->item2) { $found++; + } } - $this->assertTrue($n==2 && $found==2); + $this->assertTrue($n == 2 && $found == 2); } public function testArrayMisc() { - $this->assertEquals($this->vector->Count,count($this->vector)); + $this->assertEquals($this->vector->Count, count($this->vector)); $this->assertTrue(isset($this->vector[1])); $this->assertFalse(isset($this->vector[2])); } diff --git a/tests/unit/framework/caching/DbCacheTest.php b/tests/unit/framework/caching/DbCacheTest.php index 253240d..523281d 100644 --- a/tests/unit/framework/caching/DbCacheTest.php +++ b/tests/unit/framework/caching/DbCacheTest.php @@ -34,7 +34,7 @@ class DbCacheTest extends CacheTest */ function getConnection($reset = true) { - if($this->_connection === null) { + if ($this->_connection === null) { $databases = $this->getParam('databases'); $params = $databases['mysql']; $db = new \yii\db\Connection; @@ -61,7 +61,7 @@ class DbCacheTest extends CacheTest */ protected function getCacheInstance() { - if($this->_cacheInstance === null) { + if ($this->_cacheInstance === null) { $this->_cacheInstance = new DbCache(array( 'db' => $this->getConnection(), )); diff --git a/tests/unit/framework/caching/FileCacheTest.php b/tests/unit/framework/caching/FileCacheTest.php index 37d3222..99e3cbc 100644 --- a/tests/unit/framework/caching/FileCacheTest.php +++ b/tests/unit/framework/caching/FileCacheTest.php @@ -15,7 +15,7 @@ class FileCacheTest extends CacheTest */ protected function getCacheInstance() { - if($this->_cacheInstance === null) { + if ($this->_cacheInstance === null) { $this->_cacheInstance = new FileCache(array( 'cachePath' => '@yiiunit/runtime/cache', )); diff --git a/tests/unit/framework/caching/MemCacheTest.php b/tests/unit/framework/caching/MemCacheTest.php index 40dba12..2855e2c 100644 --- a/tests/unit/framework/caching/MemCacheTest.php +++ b/tests/unit/framework/caching/MemCacheTest.php @@ -15,11 +15,11 @@ class MemCacheTest extends CacheTest */ protected function getCacheInstance() { - if(!extension_loaded("memcache")) { + if (!extension_loaded("memcache")) { $this->markTestSkipped("memcache not installed. Skipping."); } - if($this->_cacheInstance === null) { + if ($this->_cacheInstance === null) { $this->_cacheInstance = new MemCache(); } return $this->_cacheInstance; diff --git a/tests/unit/framework/caching/MemCachedTest.php b/tests/unit/framework/caching/MemCachedTest.php index c9e437c..66dfb50 100644 --- a/tests/unit/framework/caching/MemCachedTest.php +++ b/tests/unit/framework/caching/MemCachedTest.php @@ -15,11 +15,11 @@ class MemCachedTest extends CacheTest */ protected function getCacheInstance() { - if(!extension_loaded("memcached")) { + if (!extension_loaded("memcached")) { $this->markTestSkipped("memcached not installed. Skipping."); } - if($this->_cacheInstance === null) { + if ($this->_cacheInstance === null) { $this->_cacheInstance = new MemCache(array( 'useMemcached' => true, )); diff --git a/tests/unit/framework/caching/WinCacheTest.php b/tests/unit/framework/caching/WinCacheTest.php index c9470bd..1b3399c 100644 --- a/tests/unit/framework/caching/WinCacheTest.php +++ b/tests/unit/framework/caching/WinCacheTest.php @@ -15,15 +15,15 @@ class WinCacheTest extends CacheTest */ protected function getCacheInstance() { - if(!extension_loaded('wincache')) { + if (!extension_loaded('wincache')) { $this->markTestSkipped("Wincache not installed. Skipping."); } - if(!ini_get('wincache.ucenabled')) { + if (!ini_get('wincache.ucenabled')) { $this->markTestSkipped("Wincache user cache disabled. Skipping."); } - if($this->_cacheInstance === null) { + if ($this->_cacheInstance === null) { $this->_cacheInstance = new WinCache(); } return $this->_cacheInstance; diff --git a/tests/unit/framework/caching/XCacheTest.php b/tests/unit/framework/caching/XCacheTest.php index b5e41a6..5e952af 100644 --- a/tests/unit/framework/caching/XCacheTest.php +++ b/tests/unit/framework/caching/XCacheTest.php @@ -15,11 +15,11 @@ class XCacheTest extends CacheTest */ protected function getCacheInstance() { - if(!function_exists("xcache_isset")) { + if (!function_exists("xcache_isset")) { $this->markTestSkipped("XCache not installed. Skipping."); } - if($this->_cacheInstance === null) { + if ($this->_cacheInstance === null) { $this->_cacheInstance = new XCache(); } return $this->_cacheInstance; diff --git a/tests/unit/framework/caching/ZendDataCacheTest.php b/tests/unit/framework/caching/ZendDataCacheTest.php index 86c06c8..20aa3fc 100644 --- a/tests/unit/framework/caching/ZendDataCacheTest.php +++ b/tests/unit/framework/caching/ZendDataCacheTest.php @@ -15,11 +15,11 @@ class ZendDataCacheTest extends CacheTest */ protected function getCacheInstance() { - if(!function_exists("zend_shm_cache_store")) { + if (!function_exists("zend_shm_cache_store")) { $this->markTestSkipped("Zend Data cache not installed. Skipping."); } - if($this->_cacheInstance === null) { + if ($this->_cacheInstance === null) { $this->_cacheInstance = new ZendDataCache(); } return $this->_cacheInstance; diff --git a/tests/unit/framework/db/CommandTest.php b/tests/unit/framework/db/CommandTest.php index 0d9652b..498df2a 100644 --- a/tests/unit/framework/db/CommandTest.php +++ b/tests/unit/framework/db/CommandTest.php @@ -140,7 +140,7 @@ class CommandTest extends \yiiunit\DatabaseTestCase $db = $this->getConnection(); // bindParam - $sql = 'INSERT INTO tbl_customer(email,name,address) VALUES (:email, :name, :address)'; + $sql = 'INSERT INTO tbl_customer(email, name, address) VALUES (:email, :name, :address)'; $command = $db->createCommand($sql); $email = 'user4@example.com'; $name = 'user4'; diff --git a/tests/unit/framework/helpers/StringHelperTest.php b/tests/unit/framework/helpers/StringHelperTest.php index 64811d1..fc76a26 100644 --- a/tests/unit/framework/helpers/StringHelperTest.php +++ b/tests/unit/framework/helpers/StringHelperTest.php @@ -40,7 +40,7 @@ class StringHelperTest extends \yii\test\TestCase 'car' => 'cars', ); - foreach($testData as $testIn => $testOut) { + foreach ($testData as $testIn => $testOut) { $this->assertEquals($testOut, StringHelper::pluralize($testIn)); $this->assertEquals(ucfirst($testOut), ucfirst(StringHelper::pluralize($testIn))); } diff --git a/yii/base/ErrorHandler.php b/yii/base/ErrorHandler.php index 98a061d..44c2ca0 100644 --- a/yii/base/ErrorHandler.php +++ b/yii/base/ErrorHandler.php @@ -83,7 +83,7 @@ class ErrorHandler extends Component } else { // if there is an error during error rendering it's useful to // display PHP error in debug mode instead of a blank screen - if(YII_DEBUG) { + if (YII_DEBUG) { ini_set('display_errors', 1); } @@ -231,7 +231,7 @@ class ErrorHandler extends Component echo '
+
-
'; } echo ' '; - if(isset($t['file'])) { + if (isset($t['file'])) { echo $this->htmlEncode($t['file']) . '(' . $t['line'] . '): '; } if (!empty($t['class'])) { diff --git a/yii/base/HttpException.php b/yii/base/HttpException.php index 948d96b..55e0531 100644 --- a/yii/base/HttpException.php +++ b/yii/base/HttpException.php @@ -100,9 +100,10 @@ class HttpException extends UserException 509 => 'Bandwidth Limit Exceeded', ); - if(isset($httpCodes[$this->statusCode])) + if (isset($httpCodes[$this->statusCode])) { return $httpCodes[$this->statusCode]; - else + } else { return \Yii::t('yii|Error'); + } } } diff --git a/yii/base/View.php b/yii/base/View.php index af65c49..b71e605 100644 --- a/yii/base/View.php +++ b/yii/base/View.php @@ -503,7 +503,7 @@ class View extends Component * A typical usage of fragment caching is as follows, * * ~~~ - * if($this->beginCache($id)) { + * if ($this->beginCache($id)) { * // ...generate content here * $this->endCache(); * } diff --git a/yii/caching/Cache.php b/yii/caching/Cache.php index 78f2854..ffc7081 100644 --- a/yii/caching/Cache.php +++ b/yii/caching/Cache.php @@ -140,7 +140,7 @@ abstract class Cache extends Component implements \ArrayAccess * this method will try to simulate it. * @param array $keys list of keys identifying the cached values * @return array list of cached values corresponding to the specified keys. The array - * is returned in terms of (key,value) pairs. + * is returned in terms of (key, value) pairs. * If a value is not cached or expired, the corresponding array value will be false. */ public function mget($keys) diff --git a/yii/console/controllers/AppController.php b/yii/console/controllers/AppController.php index 17f7420..0d31776 100644 --- a/yii/console/controllers/AppController.php +++ b/yii/console/controllers/AppController.php @@ -39,7 +39,7 @@ class AppController extends Controller { parent::init(); - if($this->templatesPath && !is_dir($this->templatesPath)) { + if ($this->templatesPath && !is_dir($this->templatesPath)) { throw new Exception('--templatesPath "'.$this->templatesPath.'" does not exist or can not be read.'); } } @@ -67,30 +67,29 @@ class AppController extends Controller public function actionCreate($path) { $path = strtr($path, '/\\', DIRECTORY_SEPARATOR); - if(strpos($path, DIRECTORY_SEPARATOR) === false) { + if (strpos($path, DIRECTORY_SEPARATOR) === false) { $path = '.'.DIRECTORY_SEPARATOR.$path; } $dir = rtrim(realpath(dirname($path)), '\\/'); - if($dir === false || !is_dir($dir)) { + if ($dir === false || !is_dir($dir)) { throw new Exception("The directory '$path' is not valid. Please make sure the parent directory exists."); } - if(basename($path) === '.') { + if (basename($path) === '.') { $this->_rootPath = $path = $dir; - } - else { + } else { $this->_rootPath = $path = $dir.DIRECTORY_SEPARATOR.basename($path); } - if($this->confirm("Create \"$this->type\" application under '$path'?")) { + if ($this->confirm("Create \"$this->type\" application under '$path'?")) { $sourceDir = $this->getSourceDir(); $config = $this->getConfig(); $list = $this->buildFileList($sourceDir, $path); - if(is_array($config)) { - foreach($config as $file => $settings) { - if(isset($settings['handler'])) { + if (is_array($config)) { + foreach ($config as $file => $settings) { + if (isset($settings['handler'])) { $list[$file]['callback'] = $settings['handler']; } } @@ -98,9 +97,9 @@ class AppController extends Controller $this->copyFiles($list); - if(is_array($config)) { - foreach($config as $file => $settings) { - if(isset($settings['permissions'])) { + if (is_array($config)) { + foreach ($config as $file => $settings) { + if (isset($settings['permissions'])) { @chmod($path.'/'.$file, $settings['permissions']); } } @@ -119,13 +118,11 @@ class AppController extends Controller $customSource = realpath($this->templatesPath.'/'.$this->type); $defaultSource = realpath($this->getDefaultTemplatesPath().'/'.$this->type); - if($customSource) { + if ($customSource) { return $customSource; - } - elseif($defaultSource) { + } elseif ($defaultSource) { return $defaultSource; - } - else { + } else { throw new Exception('Unable to locate the source directory for "'.$this->type.'".'); } } @@ -143,13 +140,13 @@ class AppController extends Controller */ protected function getConfig() { - if($this->_config===null) { + if ($this->_config===null) { $this->_config = require $this->getDefaultTemplatesPath().'/config.php'; - if($this->templatesPath && file_exists($this->templatesPath)) { + if ($this->templatesPath && file_exists($this->templatesPath)) { $this->_config = array_merge($this->_config, require $this->templatesPath.'/config.php'); } } - if(isset($this->_config[$this->type])) { + if (isset($this->_config[$this->type])) { return $this->_config[$this->type]; } } @@ -185,13 +182,13 @@ class AppController extends Controller $n1 = count($segs1); $n2 = count($segs2); - for($i=0; $i<$n1 && $i<$n2; ++$i) { - if($segs1[$i] !== $segs2[$i]) { + for ($i = 0; $i < $n1 && $i < $n2; ++$i) { + if ($segs1[$i] !== $segs2[$i]) { break; } } - if($i===0) { + if ($i===0) { return "'".$path1."'"; } $up=''; @@ -228,48 +225,44 @@ class AppController extends Controller protected function copyFiles($fileList) { $overwriteAll = false; - foreach($fileList as $name=>$file) { + foreach ($fileList as $name => $file) { $source = strtr($file['source'], '/\\', DIRECTORY_SEPARATOR); $target = strtr($file['target'], '/\\', DIRECTORY_SEPARATOR); $callback = isset($file['callback']) ? $file['callback'] : null; $params = isset($file['params']) ? $file['params'] : null; - if(is_dir($source)) { + if (is_dir($source)) { if (!is_dir($target)) { mkdir($target, 0777, true); } continue; } - if($callback !== null) { + if ($callback !== null) { $content = call_user_func($callback, $source, $params); - } - else { + } else { $content = file_get_contents($source); } - if(is_file($target)) { - if($content === file_get_contents($target)) { + if (is_file($target)) { + if ($content === file_get_contents($target)) { echo " unchanged $name\n"; continue; } - if($overwriteAll) { + if ($overwriteAll) { echo " overwrite $name\n"; } else { echo " exist $name\n"; echo " ...overwrite? [Yes|No|All|Quit] "; $answer = trim(fgets(STDIN)); - if(!strncasecmp($answer, 'q', 1)) { + if (!strncasecmp($answer, 'q', 1)) { return; - } - elseif(!strncasecmp($answer, 'y', 1)) { + } elseif (!strncasecmp($answer, 'y', 1)) { echo " overwrite $name\n"; - } - elseif(!strncasecmp($answer, 'a', 1)) { + } elseif (!strncasecmp($answer, 'a', 1)) { echo " overwrite $name\n"; $overwriteAll = true; - } - else { + } else { echo " skip $name\n"; continue; } @@ -303,8 +296,8 @@ class AppController extends Controller { $list = array(); $handle = opendir($sourceDir); - while(($file = readdir($handle)) !== false) { - if(in_array($file, array('.', '..', '.svn', '.gitignore', '.hgignore')) || in_array($file, $ignoreFiles)) { + while (($file = readdir($handle)) !== false) { + if (in_array($file, array('.', '..', '.svn', '.gitignore', '.hgignore')) || in_array($file, $ignoreFiles)) { continue; } $sourcePath = $sourceDir.DIRECTORY_SEPARATOR.$file; @@ -314,7 +307,7 @@ class AppController extends Controller 'source' => $sourcePath, 'target' => $targetPath, ); - if(is_dir($sourcePath)) { + if (is_dir($sourcePath)) { $list = array_merge($list, self::buildFileList($sourcePath, $targetPath, $name, $ignoreFiles, $renameMap)); } } diff --git a/yii/console/controllers/CacheController.php b/yii/console/controllers/CacheController.php index 6765f9b..b171780 100644 --- a/yii/console/controllers/CacheController.php +++ b/yii/console/controllers/CacheController.php @@ -34,11 +34,11 @@ class CacheController extends Controller { /** @var $cache Cache */ $cache = \Yii::$app->getComponent($component); - if(!$cache || !$cache instanceof Cache) { + if (!$cache || !$cache instanceof Cache) { throw new Exception('Application component "'.$component.'" is not defined or not a cache.'); } - if(!$cache->flush()) { + if (!$cache->flush()) { throw new Exception('Unable to flush cache.'); } diff --git a/yii/console/controllers/MessageController.php b/yii/console/controllers/MessageController.php index e010b55..defd219 100644 --- a/yii/console/controllers/MessageController.php +++ b/yii/console/controllers/MessageController.php @@ -57,70 +57,80 @@ class MessageController extends Controller */ public function actionIndex($config) { - if(!is_file($config)) + if (!is_file($config)) { $this->usageError("the configuration file {$config} does not exist."); + } - $config=require_once($config); + $config = require_once($config); $translator='Yii::t'; extract($config); - if(!isset($sourcePath,$messagePath,$languages)) + if (!isset($sourcePath, $messagePath, $languages)) { $this->usageError('The configuration file must specify "sourcePath", "messagePath" and "languages".'); - if(!is_dir($sourcePath)) + } + if (!is_dir($sourcePath)) { $this->usageError("The source path $sourcePath is not a valid directory."); - if(!is_dir($messagePath)) + } + if (!is_dir($messagePath)) { $this->usageError("The message path $messagePath is not a valid directory."); - if(empty($languages)) + } + if (empty($languages)) { $this->usageError("Languages cannot be empty."); + } - if(!isset($overwrite)) + if (!isset($overwrite)) { $overwrite = false; - - if(!isset($removeOld)) + } + if (!isset($removeOld)) { $removeOld = false; - - if(!isset($sort)) + } + if (!isset($sort)) { $sort = false; + } - $options=array(); - if(isset($fileTypes)) - $options['fileTypes']=$fileTypes; - if(isset($exclude)) - $options['exclude']=$exclude; - $files=CFileHelper::findFiles(realpath($sourcePath),$options); + $options = array(); + if (isset($fileTypes)) { + $options['fileTypes'] = $fileTypes; + } + if (isset($exclude)) { + $options['exclude'] = $exclude; + } + $files = CFileHelper::findFiles(realpath($sourcePath), $options); - $messages=array(); - foreach($files as $file) - $messages=array_merge_recursive($messages,$this->extractMessages($file,$translator)); + $messages = array(); + foreach ($files as $file) { + $messages = array_merge_recursive($messages, $this->extractMessages($file, $translator)); + } - foreach($languages as $language) - { - $dir=$messagePath.DIRECTORY_SEPARATOR.$language; - if(!is_dir($dir)) + foreach ($languages as $language) { + $dir = $messagePath . DIRECTORY_SEPARATOR . $language; + if (!is_dir($dir)) { @mkdir($dir); - foreach($messages as $category=>$msgs) - { - $msgs=array_values(array_unique($msgs)); - $this->generateMessageFile($msgs,$dir.DIRECTORY_SEPARATOR.$category.'.php',$overwrite,$removeOld,$sort); + } + foreach ($messages as $category => $msgs) { + $msgs = array_values(array_unique($msgs)); + $this->generateMessageFile($msgs, $dir . DIRECTORY_SEPARATOR . $category . '.php', $overwrite, $removeOld, $sort); } } } - protected function extractMessages($fileName,$translator) + protected function extractMessages($fileName, $translator) { echo "Extracting messages from $fileName...\n"; - $subject=file_get_contents($fileName); - $n=preg_match_all('/\b'.$translator.'\s*\(\s*(\'.*?(?$translation) - { - if(!isset($merged[$message]) && !isset($todo[$message]) && !$removeOld) + foreach ($translated as $message => $translation) { + if (!isset($merged[$message]) && !isset($todo[$message]) && !$removeOld) { - if(substr($translation,0,2)==='@@' && substr($translation,-2)==='@@') + if (substr($translation, 0, 2) === '@@' && substr($translation, -2) === '@@') { $todo[$message]=$translation; - else - $todo[$message]='@@'.$translation.'@@'; + } else { + $todo[$message] = '@@' . $translation . '@@'; + } } } - $merged=array_merge($todo,$merged); - if($sort) + $merged = array_merge($todo, $merged); + if ($sort) { ksort($merged); - if($overwrite === false) - $fileName.='.merged'; + } + if (false === $overwrite) { + $fileName .= '.merged'; + } echo "translation merged.\n"; - } - else - { - $merged=array(); - foreach($messages as $message) - $merged[$message]=''; + } else { + $merged = array(); + foreach ($messages as $message) { + $merged[$message] = ''; + } ksort($merged); echo "saved.\n"; } - $array=str_replace("\r",'',var_export($merged,true)); - $content=<<1, 'status'=>2)` generates `(type=1) AND (status=2)`. - * - `array('id'=>array(1,2,3), 'status'=>2)` generates `(id IN (1,2,3)) AND (status=2)`. - * - `array('status'=>null) generates `status IS NULL`. + * - `array('type' => 1, 'status' => 2)` generates `(type = 1) AND (status = 2)`. + * - `array('id' => array(1, 2, 3), 'status' => 2)` generates `(id IN (1, 2, 3)) AND (status = 2)`. + * - `array('status' => null) generates `status IS NULL`. * * A condition in operator format generates the SQL expression according to the specified operator, which * can be one of the followings: diff --git a/yii/helpers/base/ArrayHelper.php b/yii/helpers/base/ArrayHelper.php index e482883..c70e63d 100644 --- a/yii/helpers/base/ArrayHelper.php +++ b/yii/helpers/base/ArrayHelper.php @@ -93,11 +93,11 @@ class ArrayHelper * Usage examples, * * ~~~ - * // $array = array('type'=>'A', 'options'=>array(1,2)); + * // $array = array('type' => 'A', 'options' => array(1, 2)); * // working with array * $type = \yii\helpers\ArrayHelper::remove($array, 'type'); * // $array content - * // $array = array('options'=>array(1,2)); + * // $array = array('options' => array(1, 2)); * ~~~ * * @param array $array the array to extract value from diff --git a/yii/logging/FileTarget.php b/yii/logging/FileTarget.php index 69799cd..2db43b5 100644 --- a/yii/logging/FileTarget.php +++ b/yii/logging/FileTarget.php @@ -81,12 +81,12 @@ class FileTarget extends Target @flock($fp, LOCK_EX); if (@filesize($this->logFile) > $this->maxFileSize * 1024) { $this->rotateFiles(); - @flock($fp,LOCK_UN); + @flock($fp, LOCK_UN); @fclose($fp); @file_put_contents($this->logFile, $text, FILE_APPEND | LOCK_EX); } else { @fwrite($fp, $text); - @flock($fp,LOCK_UN); + @flock($fp, LOCK_UN); @fclose($fp); } } diff --git a/yii/renderers/SmartyViewRenderer.php b/yii/renderers/SmartyViewRenderer.php index c6147c0..ac66e0d 100644 --- a/yii/renderers/SmartyViewRenderer.php +++ b/yii/renderers/SmartyViewRenderer.php @@ -63,7 +63,7 @@ class SmartyViewRenderer extends ViewRenderer */ public function smarty_function_path($params, \Smarty_Internal_Template $template) { - if(!isset($params['route'])) { + if (!isset($params['route'])) { trigger_error("path: missing 'route' parameter"); } diff --git a/yii/views/exception.php b/yii/views/exception.php index f2aced0..0f26ed7 100644 --- a/yii/views/exception.php +++ b/yii/views/exception.php @@ -191,16 +191,15 @@ $title = $context->htmlEncode($exception instanceof \yii\base\Exception ? $excep var traceReg = new RegExp("(^|\\s)trace-file(\\s|$)"); var collapsedReg = new RegExp("(^|\\s)collapsed(\\s|$)"); -var e = document.getElementsByTagName("div"); -for(var j=0,len=e.length;jExample: *
 	 * request->xSendFile('/home/user/Pictures/picture1.jpg',array(
-	 *        'saveName'=>'image1.jpg',
-	 *        'mimeType'=>'image/jpeg',
-	 *        'terminate'=>false,
+	 *    Yii::app()->request->xSendFile('/home/user/Pictures/picture1.jpg', array(
+	 *        'saveName' => 'image1.jpg',
+	 *        'mimeType' => 'image/jpeg',
+	 *        'terminate' => false,
 	 *    ));
 	 * ?>
 	 * 
diff --git a/yii/web/Sort.php b/yii/web/Sort.php index 324e733..6014a3e 100644 --- a/yii/web/Sort.php +++ b/yii/web/Sort.php @@ -50,7 +50,7 @@ use yii\helpers\Html; * // display links leading to sort actions * echo $sort->link('name', 'Name') . ' | ' . $sort->link('age', 'Age'); * - * foreach($models as $model) { + * foreach ($models as $model) { * // display $model here * } * ~~~ diff --git a/yii/widgets/ActiveField.php b/yii/widgets/ActiveField.php index 9f3f201..55357a3 100644 --- a/yii/widgets/ActiveField.php +++ b/yii/widgets/ActiveField.php @@ -144,7 +144,7 @@ class ActiveField extends Component } } if (!empty($validators)) { - $options['validate'] = new JsExpression("function(attribute,value,messages){" . implode('', $validators) . '}'); + $options['validate'] = new JsExpression("function(attribute, value, messages) {" . implode('', $validators) . '}'); } } diff --git a/yii/yiic.php b/yii/yiic.php index 3be0436..3803455 100644 --- a/yii/yiic.php +++ b/yii/yiic.php @@ -7,7 +7,7 @@ * @license http://www.yiiframework.com/license/ */ -if(!ini_get('date.timezone')) { +if (!ini_get('date.timezone')) { date_default_timezone_set('UTC'); }