Browse Source

CS fixes.

tags/2.0.0-beta
resurtm 12 years ago
parent
commit
5575f53657
  1. 2
      apps/bootstrap/index.php
  2. 2
      apps/bootstrap/protected/views/site/contact.php
  3. 2
      docs/guide/performance.md
  4. 123
      tests/unit/framework/base/DictionaryTest.php
  5. 2
      tests/unit/framework/base/ModelTest.php
  6. 133
      tests/unit/framework/base/VectorTest.php
  7. 4
      tests/unit/framework/caching/DbCacheTest.php
  8. 2
      tests/unit/framework/caching/FileCacheTest.php
  9. 4
      tests/unit/framework/caching/MemCacheTest.php
  10. 4
      tests/unit/framework/caching/MemCachedTest.php
  11. 6
      tests/unit/framework/caching/WinCacheTest.php
  12. 4
      tests/unit/framework/caching/XCacheTest.php
  13. 4
      tests/unit/framework/caching/ZendDataCacheTest.php
  14. 2
      tests/unit/framework/db/CommandTest.php
  15. 2
      tests/unit/framework/helpers/StringHelperTest.php
  16. 4
      yii/base/ErrorHandler.php
  17. 5
      yii/base/HttpException.php
  18. 2
      yii/base/View.php
  19. 2
      yii/caching/Cache.php
  20. 77
      yii/console/controllers/AppController.php
  21. 4
      yii/console/controllers/CacheController.php
  22. 158
      yii/console/controllers/MessageController.php
  23. 2
      yii/db/DataReader.php
  24. 6
      yii/db/Query.php
  25. 4
      yii/helpers/base/ArrayHelper.php
  26. 4
      yii/logging/FileTarget.php
  27. 2
      yii/renderers/SmartyViewRenderer.php
  28. 17
      yii/views/exception.php
  29. 2
      yii/web/Pagination.php
  30. 8
      yii/web/Response.php
  31. 2
      yii/web/Sort.php
  32. 2
      yii/widgets/ActiveField.php
  33. 2
      yii/yiic.php

2
apps/bootstrap/index.php

@ -1,5 +1,5 @@
<?php
if(!ini_get('date.timezone')) {
if (!ini_get('date.timezone')) {
date_default_timezone_set('UTC');
}

2
apps/bootstrap/protected/views/site/contact.php

@ -13,7 +13,7 @@ $this->params['breadcrumbs'][] = $this->title;
?>
<h1><?php echo Html::encode($this->title); ?></h1>
<?php if(Yii::$app->session->hasFlash('contactFormSubmitted')): ?>
<?php if (Yii::$app->session->hasFlash('contactFormSubmitted')): ?>
<div class="alert alert-success">
Thank you for contacting us. We will respond to you as soon as possible.
</div>

2
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']."<br>";
}
```

123
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']));
}

2
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(

133
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]));
}

4
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(),
));

2
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',
));

4
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;

4
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,
));

6
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;

4
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;

4
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;

2
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';

2
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)));
}

4
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 '<div class="plus">+</div><div class="minus">-</div>';
}
echo '&nbsp;';
if(isset($t['file'])) {
if (isset($t['file'])) {
echo $this->htmlEncode($t['file']) . '(' . $t['line'] . '): ';
}
if (!empty($t['class'])) {

5
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');
}
}
}

2
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();
* }

2
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)

77
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));
}
}

4
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.');
}

158
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*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*,\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*[,\)]/s',$subject,$matches,PREG_SET_ORDER);
$messages=array();
for($i=0;$i<$n;++$i)
{
if(($pos=strpos($matches[$i][1],'.'))!==false)
$category=substr($matches[$i][1],$pos+1,-1);
else
$category=substr($matches[$i][1],1,-1);
$message=$matches[$i][2];
$messages[$category][]=eval("return $message;"); // use eval to eliminate quote escape
$subject = file_get_contents($fileName);
$n = preg_match_all(
'/\b' . $translator . '\s*\(\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*,\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*[,\)]/s',
$subject, $matches, PREG_SET_ORDER);
$messages = array();
for ($i = 0; $i < $n; ++$i) {
if (($pos = strpos($matches[$i][1], '.')) !== false) {
$category=substr($matches[$i][1], $pos + 1, -1);
} else {
$category=substr($matches[$i][1], 1, -1);
}
$message = $matches[$i][2];
$messages[$category][] = eval("return $message;"); // use eval to eliminate quote escape
}
return $messages;
}
@ -128,58 +138,58 @@ class MessageController extends Controller
protected function generateMessageFile($messages,$fileName,$overwrite,$removeOld,$sort)
{
echo "Saving messages to $fileName...";
if(is_file($fileName))
{
$translated=require($fileName);
if (is_file($fileName)) {
$translated = require($fileName);
sort($messages);
ksort($translated);
if(array_keys($translated)==$messages)
{
if (array_keys($translated) == $messages) {
echo "nothing new...skipped.\n";
return;
}
$merged=array();
$untranslated=array();
foreach($messages as $message)
{
if(!empty($translated[$message]))
$merged[$message]=$translated[$message];
else
$untranslated[]=$message;
$merged = array();
$untranslated = array();
foreach ($messages as $message) {
if (!empty($translated[$message])) {
$merged[$message] = $translated[$message];
} else {
$untranslated[] = $message;
}
}
ksort($merged);
sort($untranslated);
$todo=array();
foreach($untranslated as $message)
$todo[$message]='';
$todo = array();
foreach ($untranslated as $message) {
$todo[$message] = '';
}
ksort($translated);
foreach($translated as $message=>$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=<<<EOD
$array = str_replace("\r", '', var_export($merged, true));
$content = <<<EOD
<?php
/**
* Message translations.

2
yii/db/DataReader.php

@ -24,7 +24,7 @@ use yii\base\InvalidCallException;
* }
*
* // equivalent to:
* foreach($reader as $row) {
* foreach ($reader as $row) {
* $rows[] = $row;
* }
*

6
yii/db/Query.php

@ -210,9 +210,9 @@ class Query extends \yii\base\Component
* an `IN` expression will be generated. And if a value is null, `IS NULL` will be used
* in the generated expression. Below are some examples:
*
* - `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`.
* - `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:

4
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

4
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);
}
}

2
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");
}

17
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;j<len;j++){
if(traceReg.test(e[j].className)){
e[j].onclick = function(){
var e = document.getElementsByTagName('div');
for (var j = 0, len = e.length; j < len; j++) {
if (traceReg.test(e[j].className)) {
e[j].onclick = function() {
var trace = this.parentNode.parentNode;
if(collapsedReg.test(trace.className)){
trace.className = trace.className.replace("collapsed", "expanded");
}
else{
trace.className = trace.className.replace("expanded", "collapsed");
if (collapsedReg.test(trace.className)) {
trace.className = trace.className.replace('collapsed', 'expanded');
} else {
trace.className = trace.className.replace('expanded', 'collapsed');
}
}
}

2
yii/web/Pagination.php

@ -42,7 +42,7 @@ use Yii;
* View:
*
* ~~~
* foreach($models as $model) {
* foreach ($models as $model) {
* // display $model here
* }
*

8
yii/web/Response.php

@ -98,10 +98,10 @@ class Response extends \yii\base\Response
* <b>Example</b>:
* <pre>
* <?php
* Yii::app()->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,
* ));
* ?>
* </pre>

2
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
* }
* ~~~

2
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) . '}');
}
}

2
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');
}

Loading…
Cancel
Save