Browse Source

Added php-cs-fixer coding standards validation to Travis CI (#14100)

* php-cs-fixer: PSR2 rule.

* php-cs-fixer: PSR2 rule - fix views.

* Travis setup refactoring.

* Add php-cs-fixer to travis cs tests.

* Fix tests on hhvm-3.12

* improve travis config

* composer update

* revert composer update

* improve travis config

* Fix CS.

* Extract config to separate classes.

* Extract config to separate classes.

* Add file header.

* Force short array syntax.

* binary_operator_spaces fixer

* Fix broken tests

* cast_spaces fixer

* concat_space fixer

* dir_constant fixer

* ereg_to_preg fixer

* function_typehint_space fixer

* hash_to_slash_comment fixer

* is_null fixer

* linebreak_after_opening_tag fixer

* lowercase_cast fixer

* magic_constant_casing fixer

* modernize_types_casting fixer

* native_function_casing fixer

* new_with_braces fixer

* no_alias_functions fixer

* no_blank_lines_after_class_opening fixer

* no_blank_lines_after_phpdoc fixer

* no_empty_comment fixer

* no_empty_phpdoc fixer

* no_empty_statement fixer

* no_extra_consecutive_blank_lines fixer

* no_leading_import_slash fixer

* no_leading_namespace_whitespace fixer

* no_mixed_echo_print fixer

* no_multiline_whitespace_around_double_arrow fixer

* no_multiline_whitespace_before_semicolons fixer

* no_php4_constructor fixer

* no_short_bool_cast fixer

* no_singleline_whitespace_before_semicolons fixer

* no_spaces_around_offset fixer

* no_trailing_comma_in_list_call fixer

* no_trailing_comma_in_singleline_array fixer

* no_unneeded_control_parentheses fixer

* no_unused_imports fixer

* no_useless_return fixer

* no_whitespace_before_comma_in_array fixer

* no_whitespace_in_blank_line fixer

* not_operator_with_successor_space fixer

* object_operator_without_whitespace fixer

* ordered_imports fixer

* php_unit_construct fixer

* php_unit_dedicate_assert fixer

* php_unit_fqcn_annotation fixer

* phpdoc_indent fixer

* phpdoc_no_access fixer

* phpdoc_no_empty_return fixer

* phpdoc_no_package fixer

* phpdoc_no_useless_inheritdoc fixer

* Fix broken tests

* phpdoc_return_self_reference fixer

* phpdoc_single_line_var_spacing fixer

* phpdoc_single_line_var_spacing fixer

* phpdoc_to_comment fixer

* phpdoc_trim fixer

* phpdoc_var_without_name fixer

* psr4 fixer

* self_accessor fixer

* short_scalar_cast fixer

* single_blank_line_before_namespace fixer

* single_quote fixer

* standardize_not_equals fixer

* ternary_operator_spaces fixer

* trailing_comma_in_multiline_array fixer

* trim_array_spaces fixer

* protected_to_private fixer

* unary_operator_spaces fixer

* whitespace_after_comma_in_array fixer

* `parent::setRules()` -> `$this->setRules()`

* blank_line_after_opening_tag fixer

* Update finder config.

* Revert changes for YiiRequirementChecker.

* Fix array formatting.

* Add missing import.

* Fix CS for new code merged from master.

* Fix some indentation issues.
tags/2.0.13
Robert Korulczyk 7 years ago committed by Alexander Makarov
parent
commit
ba0ab403b5
  1. 29
      .php_cs
  2. 185
      .travis.yml
  3. 35
      build/controllers/PhpDocController.php
  4. 88
      build/controllers/ReleaseController.php
  5. 24
      build/controllers/Utf8Controller.php
  6. 6
      composer.json
  7. 1056
      composer.lock
  8. 1
      cs/TODO.md
  9. 174
      cs/src/YiiConfig.php
  10. 39
      cs/src/YiisoftConfig.php
  11. 4
      framework/BaseYii.php
  12. 2
      framework/Yii.php
  13. 4
      framework/base/Application.php
  14. 2
      framework/base/Component.php
  15. 3
      framework/base/ErrorHandler.php
  16. 2
      framework/base/Event.php
  17. 10
      framework/base/Model.php
  18. 6
      framework/base/Module.php
  19. 6
      framework/base/Security.php
  20. 2
      framework/base/Widget.php
  21. 2
      framework/base/WidgetEvent.php
  22. 2
      framework/behaviors/SluggableBehavior.php
  23. 2
      framework/caching/Cache.php
  24. 5
      framework/caching/CacheInterface.php
  25. 6
      framework/caching/DbCache.php
  26. 4
      framework/caching/MemCache.php
  27. 1
      framework/caching/migrations/m150909_153426_cache_init.php
  28. 2
      framework/captcha/Captcha.php
  29. 2
      framework/console/Controller.php
  30. 2
      framework/console/ErrorHandler.php
  31. 4
      framework/console/controllers/AssetController.php
  32. 3
      framework/console/controllers/BaseMigrateController.php
  33. 6
      framework/console/controllers/CacheController.php
  34. 10
      framework/console/controllers/FixtureController.php
  35. 2
      framework/console/controllers/HelpController.php
  36. 16
      framework/console/controllers/MessageController.php
  37. 4
      framework/data/ActiveDataProvider.php
  38. 2
      framework/data/SqlDataProvider.php
  39. 15
      framework/db/ActiveQuery.php
  40. 2
      framework/db/ActiveQueryTrait.php
  41. 4
      framework/db/ActiveRelationTrait.php
  42. 16
      framework/db/BaseActiveRecord.php
  43. 2
      framework/db/ColumnSchema.php
  44. 2
      framework/db/Query.php
  45. 1
      framework/db/QueryBuilder.php
  46. 2
      framework/db/QueryTrait.php
  47. 5
      framework/db/Schema.php
  48. 2
      framework/db/SchemaBuilderTrait.php
  49. 2
      framework/db/TableSchema.php
  50. 2
      framework/db/cubrid/Schema.php
  51. 2
      framework/db/mssql/PDO.php
  52. 4
      framework/db/mysql/Schema.php
  53. 1
      framework/db/oci/QueryBuilder.php
  54. 1
      framework/db/oci/Schema.php
  55. 2
      framework/db/pgsql/Schema.php
  56. 3
      framework/db/sqlite/QueryBuilder.php
  57. 4
      framework/db/sqlite/Schema.php
  58. 3
      framework/di/Container.php
  59. 2
      framework/di/NotInstantiableException.php
  60. 2
      framework/di/ServiceLocator.php
  61. 2
      framework/filters/AccessControl.php
  62. 6
      framework/filters/AccessRule.php
  63. 2
      framework/filters/ContentNegotiator.php
  64. 4
      framework/filters/Cors.php
  65. 2
      framework/filters/HttpCache.php
  66. 2
      framework/filters/PageCache.php
  67. 4
      framework/filters/auth/AuthInterface.php
  68. 4
      framework/filters/auth/AuthMethod.php
  69. 2
      framework/filters/auth/CompositeAuth.php
  70. 4
      framework/grid/DataColumn.php
  71. 8
      framework/grid/GridView.php
  72. 1
      framework/helpers/BaseConsole.php
  73. 10
      framework/helpers/BaseFormatConverter.php
  74. 2
      framework/helpers/BaseHtml.php
  75. 2
      framework/helpers/BaseJson.php
  76. 6
      framework/i18n/DbMessageSource.php
  77. 4
      framework/i18n/Formatter.php
  78. 2
      framework/i18n/GettextPoFile.php
  79. 2
      framework/log/DbTarget.php
  80. 6
      framework/log/Logger.php
  81. 2
      framework/mail/BaseMessage.php
  82. 2
      framework/mutex/DbMutex.php
  83. 6
      framework/mutex/OracleMutex.php
  84. 47
      framework/rbac/DbManager.php
  85. 3
      framework/rbac/PhpManager.php
  86. 1
      framework/rbac/Role.php
  87. 2
      framework/rbac/migrations/m140506_102106_rbac_init.php
  88. 10
      framework/requirements/requirements.php
  89. 6
      framework/requirements/views/console/index.php
  90. 2
      framework/rest/Controller.php
  91. 2
      framework/test/DbFixture.php
  92. 2
      framework/validators/EachValidator.php
  93. 2
      framework/validators/EmailValidator.php
  94. 4
      framework/validators/ExistValidator.php
  95. 3
      framework/validators/FileValidator.php
  96. 1
      framework/validators/IpValidator.php
  97. 2
      framework/validators/NumberValidator.php
  98. 2
      framework/validators/RegularExpressionValidator.php
  99. 9
      framework/validators/UniqueValidator.php
  100. 2
      framework/validators/UrlValidator.php
  101. Some files were not shown because too many files have changed in this diff Show More

29
.php_cs

@ -0,0 +1,29 @@
<?php
if (!class_exists('yii\cs\YiisoftConfig', true)) {
// @todo change error message
fwrite(STDERR, "Your php-cs-version is outdated: please upgrade it.\n");
die(16);
}
return yii\cs\YiisoftConfig::create()
->setCacheFile(__DIR__ . '/tests/runtime/php_cs.cache')
->mergeRules([
'braces' => [
'allow_single_line_closure' => true,
],
])
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('docs')
->exclude('apps')
->exclude('extensions')
// requirement checker should work even on PHP 4.3, so it needs special treatment
->exclude('framework/requirements')
->notPath('framework/classes.php')
->notPath('framework/helpers/mimeTypes.php')
->notPath('framework/views/messageConfig.php')
// temporary disable messages processing - conflicts with header fixer
->exclude('framework/messages')
);

185
.travis.yml

@ -23,17 +23,54 @@ sudo: false
language: php
php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- nightly
env:
global:
- DEFAULT_COMPOSER_FLAGS="--prefer-dist --no-interaction --no-progress --optimize-autoloader"
- TASK_TESTS_PHP=1
- TASK_TESTS_JS=0
- TASK_TESTS_CS=0
- TASK_TESTS_COVERAGE=0
services:
- memcached
- mysql
- postgresql
# cache vendor dirs
cache:
directories:
- vendor
- $HOME/.composer/cache
- $HOME/.npm
# try running against postgres 9.3
addons:
postgresql: "9.3"
code_climate:
repo_token: 2935307212620b0e2228ab67eadd92c9f5501ddb60549d0d86007a354d56915b
matrix:
fast_finish: true
include:
# test coding standards
- php: 7.1
env: TASK_TESTS_PHP=0 TASK_TESTS_CS=1
# overwrite services used for PHP tests
services:
# run tests coverage on PHP 7.1
- php: 7.1
env: TASK_TESTS_COVERAGE=1
- php: 7.0
- php: 5.6
- php: 5.5
- php: 5.4
# Test against HHVM 3.12 LTS version by using trusty
- php: hhvm-3.12
sudo: true
@ -49,6 +86,7 @@ matrix:
- mysql-client-5.6
services:
- mysql
# test against the latest HHVM version by using a newer image
- php: hhvm
sudo: true
@ -66,98 +104,111 @@ matrix:
services:
- mysql
- postgresql
- php: nightly
# have a separate branch for javascript tests
- language: node_js
node_js: 6
env: TASK_TESTS_PHP=0 TASK_TESTS_JS=1
dist: trusty
# overwrite php related settings
php:
# overwrite services used for PHP tests
services:
addons:
install:
- travis_retry npm install
# disable xdebug for performance in composer
- phpenv config-rm xdebug.ini || echo "xdebug is not installed"
- travis_retry composer self-update && composer --version
- travis_retry composer install --prefer-dist --no-interaction
before_script:
- node --version
- npm --version
- php --version
- composer --version
script: npm test
after_script:
allow_failures:
- php: nightly
services:
- memcached
- mysql
- postgresql
# cache vendor dirs
cache:
directories:
- vendor
- $HOME/.composer/cache
- $HOME/.npm
# try running against postgres 9.3
addons:
postgresql: "9.3"
code_climate:
repo_token: 2935307212620b0e2228ab67eadd92c9f5501ddb60549d0d86007a354d56915b
install:
- |
if [[ $TRAVIS_PHP_VERSION != '7.1' && $TRAVIS_PHP_VERSION != hhv* ]]; then
if [[ $TASK_TESTS_COVERAGE != 1 && $TRAVIS_PHP_VERSION != hhv* ]]; then
# disable xdebug for performance reasons when code coverage is not needed. note: xdebug on hhvm is disabled by default
phpenv config-rm xdebug.ini || echo "xdebug is not installed"
fi
- travis_retry composer self-update && composer --version
# install composer dependencies
- travis_retry composer self-update
- export PATH="$HOME/.composer/vendor/bin:$PATH"
# core framework:
- travis_retry composer install --prefer-dist --no-interaction
- tests/data/travis/apc-setup.sh
- tests/data/travis/memcache-setup.sh
- tests/data/travis/imagick-setup.sh
- |
if [[ $TRAVIS_PHP_VERSION == "hhvm-3.12" ]]; then
# remove php-cs-fixer from composer dependencies on hhvm-3.12 - php-cs-fixer requires at least hhvm-3.18
composer remove friendsofphp/php-cs-fixer --dev
fi
- travis_retry composer install $DEFAULT_COMPOSER_FLAGS
# setup PHP extension
- |
if [ $TASK_TESTS_PHP == 1 ]; then
tests/data/travis/apc-setup.sh
tests/data/travis/memcache-setup.sh
tests/data/travis/imagick-setup.sh
fi
# setup JS test
- |
if [ $TASK_TESTS_JS == 1 ]; then
travis_retry npm install
fi
before_script:
# Disable the HHVM JIT for faster Unit Testing
- if [[ $TRAVIS_PHP_VERSION = hhv* ]]; then echo 'hhvm.jit = 0' >> /etc/hhvm/php.ini; fi
# show some versions and env information
- php -r "echo INTL_ICU_VERSION . \"\n\";"
- php -r "echo INTL_ICU_DATA_VERSION . \"\n\";"
- mysql --version
- psql --version
- php --version
- composer --version
- |
if [ $TASK_TESTS_PHP == 1 ]; then
php -r "echo INTL_ICU_VERSION . \"\n\";"
php -r "echo INTL_ICU_DATA_VERSION . \"\n\";"
psql --version
mysql --version
fi
- |
if [ $TASK_TESTS_JS == 1 ]; then
node --version
npm --version
fi
# initialize databases
- travis_retry mysql -e 'CREATE DATABASE `yiitest`;';
- mysql -e "CREATE USER 'travis'@'localhost' IDENTIFIED WITH mysql_native_password;";
- mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'travis'@'localhost' WITH GRANT OPTION;";
- psql -U postgres -c 'CREATE DATABASE yiitest;';
- |
if [ $TASK_TESTS_PHP == 1 ]; then
travis_retry mysql -e 'CREATE DATABASE `yiitest`;';
mysql -e "CREATE USER 'travis'@'localhost' IDENTIFIED WITH mysql_native_password;";
mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'travis'@'localhost' WITH GRANT OPTION;";
psql -U postgres -c 'CREATE DATABASE yiitest;';
fi
# enable code coverage on PHP 7.1, only one PHP version needs to generate coverage data
# enable code coverage
- |
if [ $TRAVIS_PHP_VERSION = '7.1' ]; then
if [ $TASK_TESTS_COVERAGE == 1 ]; then
PHPUNIT_FLAGS="--coverage-clover=coverage.clover"
fi
script:
# ensure no files contain UTF-8 byte order mark
- if ! grep -rlI $'\xEF\xBB\xBF' framework/ ; then echo "no utf8 BOM found"; else echo "found utf8 BOM in some files. See above."; exit 1; fi
# validate composer.json
- composer validate --no-check-lock
- cd framework && composer validate --no-check-lock && cd ..
# run PHPUnit
- vendor/bin/phpunit --verbose $PHPUNIT_FLAGS --exclude-group mssql,oci,wincache,xcache,zenddata,cubrid
# test coding standards
- |
if [ $TASK_TESTS_CS == 1 ]; then
composer validate --no-check-lock
cd framework && composer validate --no-check-lock && cd ..
vendor/bin/php-cs-fixer --diff --dry-run -v fix
fi
# PHP tests
- |
if [ $TASK_TESTS_PHP == 1 ]; then
vendor/bin/phpunit --verbose $PHPUNIT_FLAGS --exclude-group mssql,oci,wincache,xcache,zenddata,cubrid
fi
# JS tests
- |
if [ $TASK_TESTS_JS == 1 ]; then
npm test
fi
after_script:
- |
if [ $TRAVIS_PHP_VERSION = '7.1' ]; then
if [ $TASK_TESTS_COVERAGE == 1 ]; then
travis_retry wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover coverage.clover
fi

35
build/controllers/PhpDocController.php

@ -103,7 +103,6 @@ class PhpDocController extends Controller
$this->stdout("\nParsed $nFilesTotal files.\n");
$this->stdout("Updated $nFilesUpdated files.\n");
}
/**
@ -173,7 +172,6 @@ class PhpDocController extends Controller
}
}
} elseif (preg_match('~extensions/([\w-]+)[\\\\/]?$~', $root, $matches)) {
$extensionPath = dirname(rtrim($root, '\\/'));
$this->setUpExtensionAliases($extensionPath);
@ -197,7 +195,6 @@ class PhpDocController extends Controller
// return [];
// }
} elseif (preg_match('~apps/([\w-]+)[\\\\/]?$~', $root, $matches)) {
$extensionPath = dirname(dirname(rtrim($root, '\\/'))) . '/extensions';
$this->setUpExtensionAliases($extensionPath);
@ -211,7 +208,6 @@ class PhpDocController extends Controller
$except[] = '/vendor/';
$except[] = '/tests/';
$except[] = '/docs/';
}
$root = FileHelper::normalizePath($root);
$options = [
@ -274,15 +270,15 @@ class PhpDocController extends Controller
$contentAfterNamespace--;
}
$lines = array_merge([
"<?php",
"/**",
" * @link http://www.yiiframework.com/",
" * @copyright Copyright (c) 2008 Yii Software LLC",
" * @license http://www.yiiframework.com/license/",
" */",
"",
'<?php',
'/**',
' * @link http://www.yiiframework.com/',
' * @copyright Copyright (c) 2008 Yii Software LLC',
' * @license http://www.yiiframework.com/license/',
' */',
'',
$namespaceLine,
""
'',
], $lines);
}
}
@ -531,7 +527,6 @@ class PhpDocController extends Controller
}
if (trim($oldDoc) != trim($newDoc)) {
$fileContent = explode("\n", file_get_contents($file));
$start = $ref->getStartLine() - 2;
$docStart = $start - count(explode("\n", $oldDoc)) + 1;
@ -621,8 +616,8 @@ class PhpDocController extends Controller
protected function generateClassPropertyDocs($fileName)
{
$phpdoc = "";
$file = str_replace("\r", "", str_replace("\t", " ", file_get_contents($fileName, true)));
$phpdoc = '';
$file = str_replace("\r", '', str_replace("\t", ' ', file_get_contents($fileName, true)));
$ns = $this->match('#\nnamespace (?<name>[\w\\\\]+);\n#', $file);
$namespace = reset($ns);
$namespace = $namespace['name'];
@ -655,7 +650,6 @@ class PhpDocController extends Controller
$className = null;
foreach ($classes as &$class) {
$className = $namespace . '\\' . $class['name'];
$gets = $this->match(
@ -756,9 +750,11 @@ class PhpDocController extends Controller
foreach ($parts as $part) {
preg_match_all($pattern . 'suU', $part, $matches, PREG_SET_ORDER);
foreach ($matches as &$set) {
foreach ($set as $i => $match)
if (is_numeric($i) /*&& $i != 0*/)
foreach ($set as $i => $match) {
if (is_numeric($i) /*&& $i != 0*/) {
unset($set[$i]);
}
}
$sets[] = $set;
}
@ -769,8 +765,9 @@ class PhpDocController extends Controller
protected function fixSentence($str)
{
// TODO fix word wrap
if ($str == '')
if ($str == '') {
return '';
}
return strtoupper(substr($str, 0, 1)) . substr($str, 1) . ($str[strlen($str) - 1] != '.' ? '.' : '');
}

88
build/controllers/ReleaseController.php

@ -127,10 +127,9 @@ class ReleaseController extends Controller
$w = $this->minWidth(array_keys($versions));
$this->stdout(str_repeat(' ', $w + 2) . "Current Version Next Version\n", Console::BOLD);
foreach ($versions as $ext => $version) {
$this->stdout($ext . str_repeat(' ', $w + 3 - mb_strlen($ext)) . $version . "");
$this->stdout($ext . str_repeat(' ', $w + 3 - mb_strlen($ext)) . $version . '');
$this->stdout(str_repeat(' ', 17 - mb_strlen($version)) . $nextVersions[$ext] . "\n");
}
}
private function minWidth($a)
@ -266,15 +265,15 @@ class ReleaseController extends Controller
$this->stdout("You are about to generate packages for the following things:\n\n");
foreach ($what as $ext) {
if (strncmp('app-', $ext, 4) === 0) {
$this->stdout(" - ");
$this->stdout(' - ');
$this->stdout(substr($ext, 4), Console::FG_RED);
$this->stdout(" application version ");
$this->stdout(' application version ');
} elseif ($ext === 'framework') {
$this->stdout(" - Yii Framework version ");
$this->stdout(' - Yii Framework version ');
} else {
$this->stdout(" - ");
$this->stdout(' - ');
$this->stdout($ext, Console::FG_RED);
$this->stdout(" extension version ");
$this->stdout(' extension version ');
}
$this->stdout($versions[$ext], Console::BOLD);
$this->stdout("\n");
@ -323,9 +322,9 @@ class ReleaseController extends Controller
$version = array_values($this->getNextVersions($this->getCurrentVersions($what), self::PATCH))[0];
$this->stdout('sorting CHANGELOG of ');
$this->stdout(reset($what), Console::BOLD);
$this->stdout(" for version ");
$this->stdout(' for version ');
$this->stdout($version, Console::BOLD);
$this->stdout("...");
$this->stdout('...');
$this->resortChangelogs($what, $version);
@ -336,15 +335,15 @@ class ReleaseController extends Controller
{
foreach ($what as $ext) {
if (strncmp('app-', $ext, 4) === 0) {
$this->stdout(" - ");
$this->stdout(' - ');
$this->stdout(substr($ext, 4), Console::FG_RED);
$this->stdout(" application version ");
$this->stdout(' application version ');
} elseif ($ext === 'framework') {
$this->stdout(" - Yii Framework version ");
$this->stdout(' - Yii Framework version ');
} else {
$this->stdout(" - ");
$this->stdout(' - ');
$this->stdout($ext, Console::FG_RED);
$this->stdout(" extension version ");
$this->stdout(' extension version ');
}
$this->stdout($newVersions[$ext], Console::BOLD);
$this->stdout(", last release was {$versions[$ext]}\n");
@ -375,7 +374,7 @@ class ReleaseController extends Controller
foreach ($what as $w) {
if (strncmp('app-', $w, 4) === 0) {
if (!empty($limit) && !in_array('app', $limit)) {
throw new Exception("Only the following types are allowed: ".implode(', ', $limit)."\n");
throw new Exception('Only the following types are allowed: ' . implode(', ', $limit) . "\n");
}
if (!is_dir($appPath = "{$this->basePath}/apps/" . substr($w, 4))) {
throw new Exception("Application path does not exist: \"{$appPath}\"\n");
@ -385,7 +384,7 @@ class ReleaseController extends Controller
}
} elseif ($w === 'framework') {
if (!empty($limit) && !in_array('framework', $limit)) {
throw new Exception("Only the following types are allowed: ".implode(', ', $limit)."\n");
throw new Exception('Only the following types are allowed: ' . implode(', ', $limit) . "\n");
}
if (!is_dir($fwPath = "{$this->basePath}/framework")) {
throw new Exception("Framework path does not exist: \"{$this->basePath}/framework\"\n");
@ -395,7 +394,7 @@ class ReleaseController extends Controller
}
} else {
if (!empty($limit) && !in_array('ext', $limit)) {
throw new Exception("Only the following types are allowed: ".implode(', ', $limit)."\n");
throw new Exception('Only the following types are allowed: ' . implode(', ', $limit) . "\n");
}
if (!is_dir($extPath = "{$this->basePath}/extensions/$w")) {
throw new Exception("Extension path for \"$w\" does not exist: \"{$this->basePath}/extensions/$w\"\n");
@ -457,10 +456,10 @@ class ReleaseController extends Controller
$this->stdout("\nIn the following you can check the above changes using git diff.\n\n");
do {
$this->runGit("git diff --color", $frameworkPath);
$this->runGit('git diff --color', $frameworkPath);
$this->stdout("\n\n\nCheck whether the above diff is okay, if not you may change things as needed before continuing.\n");
$this->stdout("You may abort the program with Ctrl + C and reset the changes by running `git checkout -- .` in the repo.\n\n");
} while (!$this->confirm("Type `yes` to continue, `no` to view git diff again. Continue?"));
} while (!$this->confirm('Type `yes` to continue, `no` to view git diff again. Continue?'));
$this->stdout("\n\n");
$this->stdout(" **** RELEASE TIME! ****\n", Console::FG_YELLOW, Console::BOLD);
@ -471,13 +470,13 @@ class ReleaseController extends Controller
$this->runGit("git commit -S -a -m \"release version $version\"", $frameworkPath);
$this->runGit("git tag -s $version -m \"version $version\"", $frameworkPath);
$this->runGit("git push", $frameworkPath);
$this->runGit("git push --tags", $frameworkPath);
$this->runGit('git push', $frameworkPath);
$this->runGit('git push --tags', $frameworkPath);
$this->stdout("\n\n");
$this->stdout("CONGRATULATIONS! You have just released ", Console::FG_YELLOW, Console::BOLD);
$this->stdout('CONGRATULATIONS! You have just released ', Console::FG_YELLOW, Console::BOLD);
$this->stdout('framework', Console::FG_RED, Console::BOLD);
$this->stdout(" version ", Console::FG_YELLOW, Console::BOLD);
$this->stdout(' version ', Console::FG_YELLOW, Console::BOLD);
$this->stdout($version, Console::BOLD);
$this->stdout("!\n\n", Console::FG_YELLOW, Console::BOLD);
@ -519,10 +518,10 @@ class ReleaseController extends Controller
$this->stdout("\n");
$this->runGit("git diff --color", $frameworkPath);
$this->runGit('git diff --color', $frameworkPath);
$this->stdout("\n\n");
$this->runGit("git commit -a -m \"prepare for next release\"", $frameworkPath);
$this->runGit("git push", $frameworkPath);
$this->runGit('git commit -a -m "prepare for next release"', $frameworkPath);
$this->runGit('git push', $frameworkPath);
$this->stdout("\n\nDONE!", Console::FG_YELLOW, Console::BOLD);
@ -544,7 +543,6 @@ class ReleaseController extends Controller
$this->stdout("- release applications: ./build/build release app-advanced\n");
$this->stdout("\n");
}
protected function releaseApplication($name, $path, $version)
@ -578,10 +576,10 @@ class ReleaseController extends Controller
$this->stdout("\nIn the following you can check the above changes using git diff.\n\n");
do {
$this->runGit("git diff --color", $path);
$this->runGit('git diff --color', $path);
$this->stdout("\n\n\nCheck whether the above diff is okay, if not you may change things as needed before continuing.\n");
$this->stdout("You may abort the program with Ctrl + C and reset the changes by running `git checkout -- .` in the repo.\n\n");
} while (!$this->confirm("Type `yes` to continue, `no` to view git diff again. Continue?"));
} while (!$this->confirm('Type `yes` to continue, `no` to view git diff again. Continue?'));
$this->stdout("\n\n");
$this->stdout(" **** RELEASE TIME! ****\n", Console::FG_YELLOW, Console::BOLD);
@ -592,13 +590,13 @@ class ReleaseController extends Controller
$this->runGit("git commit -S -a -m \"release version $version\"", $path);
$this->runGit("git tag -s $version -m \"version $version\"", $path);
$this->runGit("git push", $path);
$this->runGit("git push --tags", $path);
$this->runGit('git push', $path);
$this->runGit('git push --tags', $path);
$this->stdout("\n\n");
$this->stdout("CONGRATULATIONS! You have just released application ", Console::FG_YELLOW, Console::BOLD);
$this->stdout('CONGRATULATIONS! You have just released application ', Console::FG_YELLOW, Console::BOLD);
$this->stdout($name, Console::FG_RED, Console::BOLD);
$this->stdout(" version ", Console::FG_YELLOW, Console::BOLD);
$this->stdout(' version ', Console::FG_YELLOW, Console::BOLD);
$this->stdout($version, Console::BOLD);
$this->stdout("!\n\n", Console::FG_YELLOW, Console::BOLD);
@ -613,10 +611,10 @@ class ReleaseController extends Controller
$nextVersion = $this->getNextVersions(["app-$name" => $version], self::PATCH); // TODO support other versions
$this->stdout("\n");
$this->runGit("git diff --color", $path);
$this->runGit('git diff --color', $path);
$this->stdout("\n\n");
$this->runGit("git commit -a -m \"prepare for next release\"", $path);
$this->runGit("git push", $path);
$this->runGit('git commit -a -m "prepare for next release"', $path);
$this->runGit('git push', $path);
$this->stdout("\n\nDONE!", Console::FG_YELLOW, Console::BOLD);
@ -696,10 +694,10 @@ class ReleaseController extends Controller
$this->stdout("\nIn the following you can check the above changes using git diff.\n\n");
do {
$this->runGit("git diff --color", $path);
$this->runGit('git diff --color', $path);
$this->stdout("\n\n\nCheck whether the above diff is okay, if not you may change things as needed before continuing.\n");
$this->stdout("You may abort the program with Ctrl + C and reset the changes by running `git checkout -- .` in the repo.\n\n");
} while (!$this->confirm("Type `yes` to continue, `no` to view git diff again. Continue?"));
} while (!$this->confirm('Type `yes` to continue, `no` to view git diff again. Continue?'));
$this->stdout("\n\n");
$this->stdout(" **** RELEASE TIME! ****\n", Console::FG_YELLOW, Console::BOLD);
@ -710,13 +708,13 @@ class ReleaseController extends Controller
$this->runGit("git commit -S -a -m \"release version $version\"", $path);
$this->runGit("git tag -s $version -m \"version $version\"", $path);
$this->runGit("git push", $path);
$this->runGit("git push --tags", $path);
$this->runGit('git push', $path);
$this->runGit('git push --tags', $path);
$this->stdout("\n\n");
$this->stdout("CONGRATULATIONS! You have just released extension ", Console::FG_YELLOW, Console::BOLD);
$this->stdout('CONGRATULATIONS! You have just released extension ', Console::FG_YELLOW, Console::BOLD);
$this->stdout($name, Console::FG_RED, Console::BOLD);
$this->stdout(" version ", Console::FG_YELLOW, Console::BOLD);
$this->stdout(' version ', Console::FG_YELLOW, Console::BOLD);
$this->stdout($version, Console::BOLD);
$this->stdout("!\n\n", Console::FG_YELLOW, Console::BOLD);
@ -730,10 +728,10 @@ class ReleaseController extends Controller
$this->stdout("done.\n", Console::FG_GREEN, Console::BOLD);
$this->stdout("\n");
$this->runGit("git diff --color", $path);
$this->runGit('git diff --color', $path);
$this->stdout("\n\n");
$this->runGit("git commit -a -m \"prepare for next release\"", $path);
$this->runGit("git push", $path);
$this->runGit('git commit -a -m "prepare for next release"', $path);
$this->runGit('git push', $path);
$this->stdout("\n\nDONE!", Console::FG_YELLOW, Console::BOLD);

24
build/controllers/Utf8Controller.php

@ -40,14 +40,12 @@ class Utf8Controller extends Controller
}
foreach ($files as $file) {
$content = file_get_contents($file);
$chars = preg_split('//u', $content, null, PREG_SPLIT_NO_EMPTY);
$line = 1;
$pos = 0;
foreach ($chars as $c) {
$ord = $this->unicodeOrd($c);
$pos++;
@ -57,7 +55,7 @@ class Utf8Controller extends Controller
}
if ($ord === false) {
$this->found("BROKEN UTF8", $c, $line, $pos, $file);
$this->found('BROKEN UTF8', $c, $line, $pos, $file);
continue;
}
@ -66,22 +64,20 @@ class Utf8Controller extends Controller
|| 0x2028 <= $ord && $ord <= 0x202E
|| 0x205f <= $ord && $ord <= 0x206F
) {
$this->found("UNSUPPORTED SPACE CHARACTER", $c, $line, $pos, $file);
$this->found('UNSUPPORTED SPACE CHARACTER', $c, $line, $pos, $file);
continue;
}
if ($ord < 0x0020 && $ord != 0x000A && $ord != 0x0009 ||
0x0080 <= $ord && $ord < 0x009F) {
$this->found("CONTROL CHARARCTER", $c, $line, $pos, $file);
$this->found('CONTROL CHARARCTER', $c, $line, $pos, $file);
continue;
}
// if ($ord > 0x009F) {
// $this->found("NON ASCII CHARARCTER", $c, $line, $pos, $file);
// continue;
// }
}
}
}
private $_foundFiles = [];
@ -109,20 +105,20 @@ class Utf8Controller extends Controller
*/
private function unicodeOrd($c)
{
$h = ord($c{0});
$h = ord($c[0]);
if ($h <= 0x7F) {
return $h;
} elseif ($h < 0xC2) {
return false;
} elseif ($h <= 0xDF) {
return ($h & 0x1F) << 6 | (ord($c{1}) & 0x3F);
return ($h & 0x1F) << 6 | (ord($c[1]) & 0x3F);
} elseif ($h <= 0xEF) {
return ($h & 0x0F) << 12 | (ord($c{1}) & 0x3F) << 6
| (ord($c{2}) & 0x3F);
return ($h & 0x0F) << 12 | (ord($c[1]) & 0x3F) << 6
| (ord($c[2]) & 0x3F);
} elseif ($h <= 0xF4) {
return ($h & 0x0F) << 18 | (ord($c{1}) & 0x3F) << 12
| (ord($c{2}) & 0x3F) << 6
| (ord($c{3}) & 0x3F);
return ($h & 0x0F) << 18 | (ord($c[1]) & 0x3F) << 12
| (ord($c[2]) & 0x3F) << 6
| (ord($c[3]) & 0x3F);
} else {
return false;
}

6
composer.json

@ -82,7 +82,8 @@
},
"require-dev": {
"phpunit/phpunit": "~4.4",
"cebe/indent": "~1.0.2"
"cebe/indent": "~1.0.2",
"friendsofphp/php-cs-fixer": "~2.2.3"
},
"repositories": [
{
@ -95,7 +96,8 @@
},
"autoload": {
"psr-4": {
"yii\\": "framework/"
"yii\\": "framework/",
"yii\\cs\\": "cs/src/"
}
},
"config": {

1056
composer.lock generated

File diff suppressed because it is too large Load Diff

1
cs/TODO.md

@ -0,0 +1 @@
This should be moved to separate package, like `yii\yii2-cs`.

174
cs/src/YiiConfig.php

@ -0,0 +1,174 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\cs;
use PhpCsFixer\Config;
use yii\helpers\ArrayHelper;
/**
* Basic rules used by Yii 2 ecosystem.
*
* @author Robert Korulczyk <robert@korulczyk.pl>
* @since 2.0.0
*/
class YiiConfig extends Config
{
/**
* {@inheritdoc}
*/
public function __construct($name = 'yii-cs-config')
{
parent::__construct($name);
$this->setRiskyAllowed(true);
$this->setRules([
'@PSR2' => true,
'array_syntax' => [
'syntax' => 'short',
],
'binary_operator_spaces' => [
'align_double_arrow' => false,
'align_equals' => false,
],
'blank_line_after_opening_tag' => true,
'cast_spaces' => true,
'concat_space' => [
'spacing' => 'one',
],
'dir_constant' => true,
'ereg_to_preg' => true,
'function_typehint_space' => true,
'hash_to_slash_comment' => true,
// 'heredoc_to_nowdoc' => true, // needs more discussion
// 'include' => true, // needs more discussion
'is_null' => [
'use_yoda_style' => false,
],
'linebreak_after_opening_tag' => true,
'lowercase_cast' => true,
'magic_constant_casing' => true,
// 'mb_str_functions' => true, // needs more discussion
// 'method_separation' => true, // conflicts with current Yii style with double line between properties and methods
'modernize_types_casting' => true,
'native_function_casing' => true,
'new_with_braces' => true,
'no_alias_functions' => true,
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
'no_empty_comment' => true,
'no_empty_phpdoc' => true,
'no_empty_statement' => true,
'no_extra_consecutive_blank_lines' => [
'tokens' => [
'break',
'continue',
// 'extra', // conflicts with current Yii style with double line between properties and methods
'return',
'throw',
'use',
'use_trait',
// 'curly_brace_block', // breaks namespaces blocks
'parenthesis_brace_block',
'square_brace_block',
],
],
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_mixed_echo_print' => true,
'no_multiline_whitespace_around_double_arrow' => true,
'no_multiline_whitespace_before_semicolons' => true,
'no_php4_constructor' => true,
'no_short_bool_cast' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_spaces_around_offset' => true,
'no_trailing_comma_in_list_call' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_unneeded_control_parentheses' => true,
'no_unused_imports' => true,
// 'no_useless_else' => true, // needs more discussion
'no_useless_return' => true,
'no_whitespace_before_comma_in_array' => true,
'no_whitespace_in_blank_line' => true,
// 'non_printable_character' => true, // breaks Formatter::asCurrency() tests
'normalize_index_brace' => true,
'object_operator_without_whitespace' => true,
// 'ordered_class_elements' => [ // needs more discussion
// 'order' => [
// 'use_trait',
// 'constant_public',
// 'constant_protected',
// 'constant_private',
// 'property_public',
// 'property_protected',
// 'property_private',
// 'construct',
// 'destruct',
// 'magic',
// ],
// ],
'ordered_imports' => [
'sortAlgorithm' => 'alpha',
'importsOrder' => [
'const',
'function',
'class',
],
],
'php_unit_construct' => true,
'php_unit_dedicate_assert' => true,
'php_unit_fqcn_annotation' => true,
// 'php_unit_strict' => true, // needs more attention
// 'phpdoc_add_missing_param_annotation' => [ // needs more attention
// 'only_untyped' => false,
// ],
'phpdoc_indent' => true,
// 'phpdoc_inline_tag' => true, // see https://github.com/yiisoft/yii2/issues/11635
'phpdoc_no_access' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_no_package' => true,
'phpdoc_no_useless_inheritdoc' => true,
// 'phpdoc_order', // may be useful, but should be configurable: https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/1602
'phpdoc_return_self_reference' => true,
'phpdoc_scalar' => true,
'phpdoc_single_line_var_spacing' => true,
// 'phpdoc_summary' => true, // needs more attention (summary should be separated by blank line from description)
// 'phpdoc_to_comment' => true, // breaks phpdoc for define('CONSTANT', $value);
'phpdoc_trim' => true,
// 'phpdoc_types' => true, // conflicts with yii\base\Object typehits https://github.com/yiisoft/yii2/pull/12699
'phpdoc_var_without_name' => true,
'protected_to_private' => true,
'psr4' => true,
'self_accessor' => true,
'short_scalar_cast' => true,
'single_blank_line_before_namespace' => true,
'single_quote' => true,
'standardize_not_equals' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline_array' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'whitespace_after_comma_in_array' => true,
]);
}
/**
* Merge current rules config with provided list of rules.
*
* @param array $rules
* @return $this
* @see setRules()
* @see ArrayHelper::merge()
*/
public function mergeRules(array $rules)
{
$this->setRules(ArrayHelper::merge($this->getRules(), $rules));
return $this;
}
}

39
cs/src/YiisoftConfig.php

@ -0,0 +1,39 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\cs;
/**
* Basic rules used by Yii 2 official packages.
*
* @author Robert Korulczyk <robert@korulczyk.pl>
* @since 2.0.0
*/
final class YiisoftConfig extends YiiConfig
{
/**
* {@inheritdoc}
*/
public function __construct()
{
parent::__construct('yiisoft-cs-config');
$header = <<<HEADER
@link http://www.yiiframework.com/
@copyright Copyright (c) 2008 Yii Software LLC
@license http://www.yiiframework.com/license/
HEADER;
$this->mergeRules([
'header_comment' => [
'header' => $header,
'commentType' => 'PHPDoc',
'separate' => 'bottom',
],
]);
}
}

4
framework/BaseYii.php

@ -10,8 +10,8 @@ namespace yii;
use yii\base\InvalidConfigException;
use yii\base\InvalidParamException;
use yii\base\UnknownClassException;
use yii\log\Logger;
use yii\di\Container;
use yii\log\Logger;
/**
* Gets the application start timestamp.
@ -474,7 +474,7 @@ class BaseYii
{
return \Yii::t('yii', 'Powered by {yii}', [
'yii' => '<a href="http://www.yiiframework.com/" rel="external">' . \Yii::t('yii',
'Yii Framework') . '</a>'
'Yii Framework') . '</a>',
]);
}

2
framework/Yii.php

@ -1,7 +1,5 @@
<?php
/**
* Yii bootstrap file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/

4
framework/base/Application.php

@ -372,7 +372,6 @@ abstract class Application extends Module
public function run()
{
try {
$this->state = self::STATE_BEFORE_REQUEST;
$this->trigger(self::EVENT_BEFORE_REQUEST);
@ -388,12 +387,9 @@ abstract class Application extends Module
$this->state = self::STATE_END;
return $response->exitStatus;
} catch (ExitException $e) {
$this->end($e->statusCode, isset($response) ? $response : null);
return $e->statusCode;
}
}

2
framework/base/Component.php

@ -533,7 +533,7 @@ class Component extends Object
$this->ensureBehaviors();
if (!empty($this->_events[$name])) {
if ($event === null) {
$event = new Event;
$event = new Event();
}
if ($event->sender === null) {
$event->sender = $this;

3
framework/base/ErrorHandler.php

@ -133,7 +133,8 @@ abstract class ErrorHandler extends Component
* @param \Exception $previousException Main exception processed in [[handleException()]].
* @since 2.0.11
*/
protected function handleFallbackExceptionMessage($exception, $previousException) {
protected function handleFallbackExceptionMessage($exception, $previousException)
{
$msg = "An Error occurred while handling another error:\n";
$msg .= (string) $exception;
$msg .= "\nPrevious exception:\n";

2
framework/base/Event.php

@ -190,7 +190,7 @@ class Event extends Object
return;
}
if ($event === null) {
$event = new static;
$event = new static();
}
$event->handled = false;
$event->name = $name;

10
framework/base/Model.php

@ -7,12 +7,12 @@
namespace yii\base;
use Yii;
use ArrayAccess;
use ArrayObject;
use ArrayIterator;
use ReflectionClass;
use ArrayObject;
use IteratorAggregate;
use ReflectionClass;
use Yii;
use yii\helpers\Inflector;
use yii\validators\RequiredValidator;
use yii\validators\Validator;
@ -372,7 +372,7 @@ class Model extends Component implements IteratorAggregate, ArrayAccess, Arrayab
*/
public function beforeValidate()
{
$event = new ModelEvent;
$event = new ModelEvent();
$this->trigger(self::EVENT_BEFORE_VALIDATE, $event);
return $event->isValid;
@ -439,7 +439,7 @@ class Model extends Component implements IteratorAggregate, ArrayAccess, Arrayab
*/
public function createValidators()
{
$validators = new ArrayObject;
$validators = new ArrayObject();
foreach ($this->rules() as $rule) {
if ($rule instanceof Validator) {
$validators->append($rule);

6
framework/base/Module.php

@ -415,7 +415,7 @@ class Module extends ServiceLocator
}
if (isset($this->_modules[$id])) {
if ($this->_modules[$id] instanceof Module) {
if ($this->_modules[$id] instanceof self) {
return $this->_modules[$id];
} elseif ($load) {
Yii::trace("Loading module: $id", __METHOD__);
@ -461,7 +461,7 @@ class Module extends ServiceLocator
if ($loadedOnly) {
$modules = [];
foreach ($this->_modules as $module) {
if ($module instanceof Module) {
if ($module instanceof self) {
$modules[] = $module;
}
}
@ -638,7 +638,7 @@ class Module extends ServiceLocator
$controller = Yii::createObject($className, [$id, $this]);
return get_class($controller) === $className ? $controller : null;
} elseif (YII_DEBUG) {
throw new InvalidConfigException("Controller class must extend from \\yii\\base\\Controller.");
throw new InvalidConfigException('Controller class must extend from \\yii\\base\\Controller.');
}
return null;
}

6
framework/base/Security.php

@ -7,8 +7,8 @@
namespace yii\base;
use yii\helpers\StringHelper;
use Yii;
use yii\helpers\StringHelper;
/**
* Security provides a set of methods to handle common security-related tasks.
@ -610,7 +610,7 @@ class Security extends Component
}
if (function_exists('password_hash')) {
/** @noinspection PhpUndefinedConstantInspection */
/* @noinspection PhpUndefinedConstantInspection */
return password_hash($password, PASSWORD_DEFAULT, ['cost' => $cost]);
}
@ -680,7 +680,7 @@ class Security extends Component
// Get a 20-byte random string
$rand = $this->generateRandomKey(20);
// Form the prefix that specifies Blowfish (bcrypt) algorithm and cost parameter.
$salt = sprintf("$2y$%02d$", $cost);
$salt = sprintf('$2y$%02d$', $cost);
// Append the random salt data in the required base64 format.
$salt .= str_replace('+', '.', substr(base64_encode($rand), 0, 22));

2
framework/base/Widget.php

@ -7,8 +7,8 @@
namespace yii\base;
use Yii;
use ReflectionClass;
use Yii;
/**
* Widget is the base class for widgets.

2
framework/base/WidgetEvent.php

@ -22,7 +22,7 @@ class WidgetEvent extends Event
*/
public $result;
/**
* @var boolean whether to continue running the widget. Event handlers of
* @var bool whether to continue running the widget. Event handlers of
* [[Widget::EVENT_BEFORE_RUN]] may set this property to decide whether
* to continue running the current widget.
*/

2
framework/behaviors/SluggableBehavior.php

@ -7,12 +7,12 @@
namespace yii\behaviors;
use Yii;
use yii\base\InvalidConfigException;
use yii\db\BaseActiveRecord;
use yii\helpers\ArrayHelper;
use yii\helpers\Inflector;
use yii\validators\UniqueValidator;
use Yii;
/**
* SluggableBehavior automatically fills the specified attribute with a value that can be used a slug in a URL.

2
framework/caching/Cache.php

@ -73,7 +73,7 @@ abstract class Cache extends Component implements CacheInterface
*/
public $serializer;
/**
* @var integer default duration in seconds before a cache entry will expire. Default value is 0, meaning infinity.
* @var int default duration in seconds before a cache entry will expire. Default value is 0, meaning infinity.
* This value is used by [[set()]] if the duration is not explicitly given.
* @since 2.0.11
*/

5
framework/caching/CacheInterface.php

@ -1,4 +1,9 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\caching;

6
framework/caching/DbCache.php

@ -101,7 +101,7 @@ class DbCache extends Cache
{
$key = $this->buildKey($key);
$query = new Query;
$query = new Query();
$query->select(['COUNT(*)'])
->from($this->cacheTable)
->where('[[id]] = :id AND ([[expire]] = 0 OR [[expire]] >' . time() . ')', [':id' => $key]);
@ -125,7 +125,7 @@ class DbCache extends Cache
*/
protected function getValue($key)
{
$query = new Query;
$query = new Query();
$query->select(['data'])
->from($this->cacheTable)
->where('[[id]] = :id AND ([[expire]] = 0 OR [[expire]] >' . time() . ')', [':id' => $key]);
@ -150,7 +150,7 @@ class DbCache extends Cache
if (empty($keys)) {
return [];
}
$query = new Query;
$query = new Query();
$query->select(['id', 'data'])
->from($this->cacheTable)
->where(['id' => $keys])

4
framework/caching/MemCache.php

@ -221,7 +221,7 @@ class MemCache extends Cache
}
if ($this->useMemcached) {
$this->_cache = $this->persistentId !== null ? new \Memcached($this->persistentId) : new \Memcached;
$this->_cache = $this->persistentId !== null ? new \Memcached($this->persistentId) : new \Memcached();
if ($this->username !== null || $this->password !== null) {
$this->_cache->setOption(\Memcached::OPT_BINARY_PROTOCOL, true);
$this->_cache->setSaslAuthData($this->username, $this->password);
@ -230,7 +230,7 @@ class MemCache extends Cache
$this->_cache->setOptions($this->options);
}
} else {
$this->_cache = new \Memcache;
$this->_cache = new \Memcache();
}
}

1
framework/caching/migrations/m150909_153426_cache_init.php

@ -17,7 +17,6 @@ use yii\db\Migration;
*/
class m150909_153426_cache_init extends Migration
{
/**
* @throws yii\base\InvalidConfigException
* @return DbCache

2
framework/captcha/Captcha.php

@ -9,9 +9,9 @@ namespace yii\captcha;
use Yii;
use yii\base\InvalidConfigException;
use yii\helpers\Url;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\helpers\Url;
use yii\widgets\InputWidget;
/**

2
framework/console/Controller.php

@ -351,7 +351,7 @@ class Controller extends \yii\base\Controller
public function optionAliases()
{
return [
'h' => 'help'
'h' => 'help',
];
}

2
framework/console/ErrorHandler.php

@ -34,7 +34,7 @@ class ErrorHandler extends \yii\base\ErrorHandler
$message = $this->formatMessage($exception->getName() . ': ') . $exception->command;
$alternatives = $exception->getSuggestedAlternatives();
if (count($alternatives) === 1) {
$message .= "\n\nDid you mean \"" . reset($alternatives) . "\"?";
$message .= "\n\nDid you mean \"" . reset($alternatives) . '"?';
} elseif (count($alternatives) > 1) {
$message .= "\n\nDid you mean one of these?\n - " . implode("\n - ", $alternatives);
}

4
framework/console/controllers/AssetController.php

@ -8,8 +8,8 @@
namespace yii\console\controllers;
use Yii;
use yii\console\Exception;
use yii\console\Controller;
use yii\console\Exception;
use yii\helpers\Console;
use yii\helpers\FileHelper;
use yii\helpers\VarDumper;
@ -766,7 +766,7 @@ EOD;
*/
private function isBundleExternal($bundle)
{
return (empty($bundle->sourcePath) && empty($bundle->basePath));
return empty($bundle->sourcePath) && empty($bundle->basePath);
}
/**

3
framework/console/controllers/BaseMigrateController.php

@ -9,11 +9,10 @@ namespace yii\console\controllers;
use Yii;
use yii\base\InvalidConfigException;
use yii\console\Exception;
use yii\console\Controller;
use yii\console\Exception;
use yii\helpers\Console;
use yii\helpers\FileHelper;
use yii\helpers\StringHelper;
/**
* BaseMigrateController is the base class for migrate controllers.

6
framework/console/controllers/CacheController.php

@ -11,8 +11,8 @@ use Yii;
use yii\caching\ApcCache;
use yii\caching\CacheInterface;
use yii\console\Controller;
use yii\helpers\Console;
use yii\console\Exception;
use yii\helpers\Console;
/**
* Allows you to flush cache.
@ -67,7 +67,6 @@ class CacheController extends Controller
* # flushes caches specified by their id: "first", "second", "third"
* yii cache/flush first second third
* ```
*
*/
public function actionFlush()
{
@ -213,7 +212,6 @@ class CacheController extends Controller
}
/**
*
* @param array $caches
*/
private function notifyFlushed($caches)
@ -294,6 +292,6 @@ class CacheController extends Controller
*/
private function canBeFlushed($className)
{
return !is_a($className, ApcCache::className(), true) || php_sapi_name() !== "cli";
return !is_a($className, ApcCache::className(), true) || php_sapi_name() !== 'cli';
}
}

10
framework/console/controllers/FixtureController.php

@ -68,7 +68,7 @@ class FixtureController extends Controller
public function options($actionID)
{
return array_merge(parent::options($actionID), [
'namespace', 'globalFixtures'
'namespace', 'globalFixtures',
]);
}
@ -135,8 +135,8 @@ class FixtureController extends Controller
if (!$foundFixtures) {
throw new Exception(
"No files were found for: \"" . implode(', ', $fixturesInput) . "\".\n" .
"Check that files exist under fixtures path: \n\"" . $this->getFixturePath() . "\"."
'No files were found for: "' . implode(', ', $fixturesInput) . "\".\n" .
"Check that files exist under fixtures path: \n\"" . $this->getFixturePath() . '".'
);
}
@ -205,8 +205,8 @@ class FixtureController extends Controller
if (!$foundFixtures) {
throw new Exception(
"No files were found for: \"" . implode(', ', $fixturesInput) . "\".\n" .
"Check that files exist under fixtures path: \n\"" . $this->getFixturePath() . "\"."
'No files were found for: "' . implode(', ', $fixturesInput) . "\".\n" .
"Check that files exist under fixtures path: \n\"" . $this->getFixturePath() . '".'
);
}

2
framework/console/controllers/HelpController.php

@ -168,8 +168,6 @@ class HelpController extends Controller
}
$this->stdout("\n");
return;
}
/**

16
framework/console/controllers/MessageController.php

@ -363,13 +363,13 @@ EOD;
protected function saveMessagesToDb($messages, $db, $sourceMessageTable, $messageTable, $removeUnused, $languages, $markUnused)
{
$currentMessages = [];
$rows = (new Query)->select(['id', 'category', 'message'])->from($sourceMessageTable)->all($db);
$rows = (new Query())->select(['id', 'category', 'message'])->from($sourceMessageTable)->all($db);
foreach ($rows as $row) {
$currentMessages[$row['category']][$row['id']] = $row['message'];
}
$currentLanguages = [];
$rows = (new Query)->select(['language'])->from($messageTable)->groupBy('language')->all($db);
$rows = (new Query())->select(['language'])->from($messageTable)->groupBy('language')->all($db);
foreach ($rows as $row) {
$currentLanguages[] = $row['language'];
}
@ -422,7 +422,7 @@ EOD;
if (!empty($missingLanguages)) {
$updatedMessages = [];
$rows = (new Query)->select(['id', 'category', 'message'])->from($sourceMessageTable)->all($db);
$rows = (new Query())->select(['id', 'category', 'message'])->from($sourceMessageTable)->all($db);
foreach ($rows as $row) {
$updatedMessages[$row['category']][$row['id']] = $row['message'];
}
@ -452,7 +452,7 @@ EOD;
->execute();
$this->stdout("deleted.\n");
} elseif ($markUnused) {
$rows = (new Query)
$rows = (new Query())
->select(['id', 'message'])
->from($sourceMessageTable)
->where(['in', 'id', $obsolete])
@ -482,7 +482,7 @@ EOD;
*/
protected function extractMessages($fileName, $translator, $ignoreCategories = [])
{
$this->stdout("Extracting messages from ");
$this->stdout('Extracting messages from ');
$this->stdout($fileName, Console::FG_CYAN);
$this->stdout("...\n");
@ -656,7 +656,7 @@ EOD;
protected function saveMessagesToPHP($messages, $dirName, $overwrite, $removeUnused, $sort, $markUnused)
{
foreach ($messages as $category => $msgs) {
$file = str_replace("\\", '/', "$dirName/$category.php");
$file = str_replace('\\', '/', "$dirName/$category.php");
$path = dirname($file);
FileHelper::createDirectory($path);
$msgs = array_values(array_unique($msgs));
@ -777,7 +777,7 @@ EOD;
*/
protected function saveMessagesToPO($messages, $dirName, $overwrite, $removeUnused, $sort, $catalog, $markUnused)
{
$file = str_replace("\\", '/', "$dirName/$catalog.po");
$file = str_replace('\\', '/', "$dirName/$catalog.po");
FileHelper::createDirectory(dirname($file));
$this->stdout("Saving messages to $file...\n");
@ -870,7 +870,7 @@ EOD;
*/
protected function saveMessagesToPOT($messages, $dirName, $catalog)
{
$file = str_replace("\\", '/', "$dirName/$catalog.pot");
$file = str_replace('\\', '/', "$dirName/$catalog.pot");
FileHelper::createDirectory(dirname($file));
$this->stdout("Saving messages to $file...\n");

4
framework/data/ActiveDataProvider.php

@ -7,9 +7,9 @@
namespace yii\data;
use yii\db\ActiveQueryInterface;
use yii\base\InvalidConfigException;
use yii\base\Model;
use yii\db\ActiveQueryInterface;
use yii\db\Connection;
use yii\db\QueryInterface;
use yii\di\Instance;
@ -177,7 +177,7 @@ class ActiveDataProvider extends BaseDataProvider
parent::setSort($value);
if (($sort = $this->getSort()) !== false && $this->query instanceof ActiveQueryInterface) {
/* @var $model Model */
$model = new $this->query->modelClass;
$model = new $this->query->modelClass();
if (empty($sort->attributes)) {
foreach ($model->attributes() as $attribute) {
$sort->attributes[$attribute] = [

2
framework/data/SqlDataProvider.php

@ -165,7 +165,7 @@ class SqlDataProvider extends BaseDataProvider
{
return (new Query([
'from' => ['sub' => "({$this->sql})"],
'params' => $this->params
'params' => $this->params,
]))->count('*', $this->db);
}
}

15
framework/db/ActiveQuery.php

@ -339,7 +339,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
return parent::queryScalar($selectExpression, $db);
}
return (new Query)->select([$selectExpression])
return (new Query())->select([$selectExpression])
->from(['c' => "({$this->sql})"])
->params($this->params)
->createCommand($db)
@ -412,7 +412,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
list(, $relation, $alias) = $matches;
$name = $relation;
$callback = function ($query) use ($callback, $alias) {
/** @var $query ActiveQuery */
/* @var $query ActiveQuery */
$query->alias($alias);
if ($callback !== null) {
call_user_func($callback, $query);
@ -435,7 +435,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
$join = $this->join;
$this->join = [];
$model = new $this->modelClass;
$model = new $this->modelClass();
foreach ($this->joinWith as $config) {
list($with, $eagerLoading, $joinType) = $config;
$this->joinWithRelations($model, $with, $joinType);
@ -515,7 +515,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
} else {
$relation = $relations[$fullName];
}
$primaryModel = new $relation->modelClass;
$primaryModel = new $relation->modelClass();
$parent = $relation;
$prefix = $fullName;
$name = $childName;
@ -590,7 +590,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
{
$via = $child->via;
$child->via = null;
if ($via instanceof ActiveQuery) {
if ($via instanceof self) {
// via table
$this->joinWithRelation($parent, $via, $joinType);
$this->joinWithRelation($via, $child, $joinType);
@ -606,7 +606,6 @@ class ActiveQuery extends Query implements ActiveQueryInterface
list($childTable, $childAlias) = $child->getTableNameAndAlias();
if (!empty($child->link)) {
if (strpos($parentAlias, '{{') === false) {
$parentAlias = '{{' . $parentAlias . '}}';
}
@ -750,7 +749,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
*/
public function viaTable($tableName, $link, callable $callable = null)
{
$relation = new ActiveQuery(get_class($this->primaryModel), [
$relation = new self(get_class($this->primaryModel), [
'from' => [$tableName],
'link' => $link,
'multiple' => true,
@ -777,7 +776,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
public function alias($alias)
{
if (empty($this->from) || count($this->from) < 2) {
list($tableName, ) = $this->getTableNameAndAlias();
list($tableName) = $this->getTableNameAndAlias();
$this->from = [$alias => $tableName];
} else {
$tableName = $this->getPrimaryTableName();

2
framework/db/ActiveQueryTrait.php

@ -162,7 +162,7 @@ trait ActiveQueryTrait
{
$primaryModel = reset($models);
if (!$primaryModel instanceof ActiveRecordInterface) {
$primaryModel = new $this->modelClass;
$primaryModel = new $this->modelClass();
}
$relations = $this->normalizeRelations($primaryModel, $with);
/* @var $relation ActiveQuery */

4
framework/db/ActiveRelationTrait.php

@ -177,7 +177,7 @@ trait ActiveRelationTrait
$relatedModel->populateRelation($this->inverseOf, $inverseRelation->multiple ? [$this->primaryModel] : $this->primaryModel);
} else {
if (!isset($inverseRelation)) {
$inverseRelation = (new $this->modelClass)->getRelation($this->inverseOf);
$inverseRelation = (new $this->modelClass())->getRelation($this->inverseOf);
}
$result[$i][$this->inverseOf] = $inverseRelation->multiple ? [$this->primaryModel] : $this->primaryModel;
}
@ -298,7 +298,7 @@ trait ActiveRelationTrait
}
$model = reset($models);
/* @var $relation ActiveQueryInterface|ActiveQuery */
$relation = $model instanceof ActiveRecordInterface ? $model->getRelation($name) : (new $this->modelClass)->getRelation($name);
$relation = $model instanceof ActiveRecordInterface ? $model->getRelation($name) : (new $this->modelClass())->getRelation($name);
if ($relation->multiple) {
$buckets = $this->buildBuckets($primaryModels, $relation->link, null, null, false);

16
framework/db/BaseActiveRecord.php

@ -7,14 +7,14 @@
namespace yii\db;
use yii\base\InvalidConfigException;
use yii\base\Event;
use yii\base\Model;
use yii\base\InvalidCallException;
use yii\base\InvalidConfigException;
use yii\base\InvalidParamException;
use yii\base\Model;
use yii\base\ModelEvent;
use yii\base\NotSupportedException;
use yii\base\UnknownMethodException;
use yii\base\InvalidCallException;
use yii\helpers\ArrayHelper;
/**
@ -934,7 +934,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
*/
public function beforeSave($insert)
{
$event = new ModelEvent;
$event = new ModelEvent();
$this->trigger($insert ? self::EVENT_BEFORE_INSERT : self::EVENT_BEFORE_UPDATE, $event);
return $event->isValid;
@ -986,7 +986,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
*/
public function beforeDelete()
{
$event = new ModelEvent;
$event = new ModelEvent();
$this->trigger(self::EVENT_BEFORE_DELETE, $event);
return $event->isValid;
@ -1160,7 +1160,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
*/
public static function instantiate($row)
{
return new static;
return new static();
}
/**
@ -1566,7 +1566,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
} catch (InvalidParamException $e) {
return $this->generateAttributeLabel($attribute);
}
$relatedModel = new $relation->modelClass;
$relatedModel = new $relation->modelClass();
}
}
@ -1606,7 +1606,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
} catch (InvalidParamException $e) {
return '';
}
$relatedModel = new $relation->modelClass;
$relatedModel = new $relation->modelClass();
}
}

2
framework/db/ColumnSchema.php

@ -137,7 +137,7 @@ class ColumnSchema extends Object
// https://github.com/yiisoft/yii2/issues/9006
return (bool) $value && $value !== "\0";
case 'double':
return (double) $value;
return (float) $value;
}
return $value;

2
framework/db/Query.php

@ -432,7 +432,7 @@ class Query extends Component implements QueryInterface
return $command->queryScalar();
} else {
return (new Query)->select([$selectExpression])
return (new self())->select([$selectExpression])
->from(['c' => $this])
->createCommand($db)
->queryScalar();

1
framework/db/QueryBuilder.php

@ -648,7 +648,6 @@ class QueryBuilder extends \yii\base\Object
*/
public function addCommentOnColumn($table, $column, $comment)
{
return 'COMMENT ON COLUMN ' . $this->db->quoteTableName($table) . '.' . $this->db->quoteColumnName($column) . ' IS ' . $this->db->quoteValue($comment);
}

2
framework/db/QueryTrait.php

@ -52,7 +52,7 @@ trait QueryTrait
*/
public $indexBy;
/**
* @var boolean whether to emulate the actual query execution, returning empty or false results.
* @var bool whether to emulate the actual query execution, returning empty or false results.
* @see emulateExecution()
* @since 2.0.11
*/

5
framework/db/Schema.php

@ -8,9 +8,9 @@
namespace yii\db;
use Yii;
use yii\base\Object;
use yii\base\NotSupportedException;
use yii\base\InvalidCallException;
use yii\base\NotSupportedException;
use yii\base\Object;
use yii\caching\CacheInterface;
use yii\caching\TagDependency;
@ -511,7 +511,6 @@ abstract class Schema extends Object
}
return implode('.', $parts);
}
/**

2
framework/db/SchemaBuilderTrait.php

@ -37,7 +37,7 @@ trait SchemaBuilderTrait
/**
* @return Connection the database connection to be used for schema building.
*/
protected abstract function getDb();
abstract protected function getDb();
/**
* Creates a primary key column.

2
framework/db/TableSchema.php

@ -7,8 +7,8 @@
namespace yii\db;
use yii\base\Object;
use yii\base\InvalidParamException;
use yii\base\Object;
/**
* TableSchema represents the metadata of a database table.

2
framework/db/cubrid/Schema.php

@ -7,9 +7,9 @@
namespace yii\db\cubrid;
use yii\db\ColumnSchema;
use yii\db\Expression;
use yii\db\TableSchema;
use yii\db\ColumnSchema;
use yii\db\Transaction;
/**

2
framework/db/mssql/PDO.php

@ -76,7 +76,7 @@ class PDO extends \PDO
return parent::getAttribute($attribute);
} catch (\PDOException $e) {
switch ($attribute) {
case PDO::ATTR_SERVER_VERSION:
case self::ATTR_SERVER_VERSION:
return $this->query("SELECT CAST(SERVERPROPERTY('productversion') AS VARCHAR)")->fetchColumn();
default:
throw $e;

4
framework/db/mysql/Schema.php

@ -7,9 +7,9 @@
namespace yii\db\mysql;
use yii\db\ColumnSchema;
use yii\db\Expression;
use yii\db\TableSchema;
use yii\db\ColumnSchema;
/**
* Schema is the class for retrieving metadata from a MySQL database (version 4.1.x and 5.x).
@ -92,7 +92,7 @@ class Schema extends \yii\db\Schema
*/
protected function loadTableSchema($name)
{
$table = new TableSchema;
$table = new TableSchema();
$this->resolveTableNames($table, $name);
if ($this->findColumns($table)) {

1
framework/db/oci/QueryBuilder.php

@ -386,5 +386,4 @@ EOD;
return $this->buildCondition(['AND', $condition], $params);
}
}

1
framework/db/oci/Schema.php

@ -172,7 +172,6 @@ SQL;
*/
protected function getTableSequenceName($tableName)
{
$sequenceNameSql = <<<SQL
SELECT
UD.REFERENCED_NAME AS SEQUENCE_NAME

2
framework/db/pgsql/Schema.php

@ -7,9 +7,9 @@
namespace yii\db\pgsql;
use yii\db\ColumnSchema;
use yii\db\Expression;
use yii\db\TableSchema;
use yii\db\ColumnSchema;
use yii\db\ViewFinderTrait;
/**

3
framework/db/sqlite/QueryBuilder.php

@ -7,10 +7,9 @@
namespace yii\db\sqlite;
use yii\db\Connection;
use yii\db\Exception;
use yii\base\InvalidParamException;
use yii\base\NotSupportedException;
use yii\db\Connection;
use yii\db\Expression;
use yii\db\Query;

4
framework/db/sqlite/Schema.php

@ -8,9 +8,9 @@
namespace yii\db\sqlite;
use yii\base\NotSupportedException;
use yii\db\ColumnSchema;
use yii\db\Expression;
use yii\db\TableSchema;
use yii\db\ColumnSchema;
use yii\db\Transaction;
/**
@ -119,7 +119,7 @@ class Schema extends \yii\db\Schema
*/
protected function loadTableSchema($name)
{
$table = new TableSchema;
$table = new TableSchema();
$table->name = $name;
$table->fullName = $name;

3
framework/di/Container.php

@ -330,7 +330,7 @@ class Container extends Component
if (strpos($class, '\\') !== false) {
$definition['class'] = $class;
} else {
throw new InvalidConfigException("A class definition requires a \"class\" member.");
throw new InvalidConfigException('A class definition requires a "class" member.');
}
}
return $definition;
@ -546,7 +546,6 @@ class Container extends Component
throw $e;
}
}
}
} elseif ($associative && isset($params[$name])) {
$args[] = $params[$name];

2
framework/di/NotInstantiableException.php

@ -7,7 +7,7 @@
namespace yii\di;
use \yii\base\InvalidConfigException;
use yii\base\InvalidConfigException;
/**
* NotInstantiableException represents an exception caused by incorrect dependency injection container

2
framework/di/ServiceLocator.php

@ -7,8 +7,8 @@
namespace yii\di;
use Yii;
use Closure;
use Yii;
use yii\base\Component;
use yii\base\InvalidConfigException;

2
framework/filters/AccessControl.php

@ -11,8 +11,8 @@ use Yii;
use yii\base\Action;
use yii\base\ActionFilter;
use yii\di\Instance;
use yii\web\User;
use yii\web\ForbiddenHttpException;
use yii\web\User;
/**
* AccessControl provides simple access control based on a set of rules.

6
framework/filters/AccessRule.php

@ -8,12 +8,12 @@
namespace yii\filters;
use Closure;
use yii\base\Component;
use yii\base\Action;
use yii\base\Component;
use yii\base\Controller;
use yii\base\InvalidConfigException;
use yii\web\User;
use yii\web\Request;
use yii\base\Controller;
use yii\web\User;
/**
* This class represents an access rule defined by the [[AccessControl]] action filter

2
framework/filters/ContentNegotiator.php

@ -11,8 +11,8 @@ use Yii;
use yii\base\ActionFilter;
use yii\base\BootstrapInterface;
use yii\base\InvalidConfigException;
use yii\web\Response;
use yii\web\Request;
use yii\web\Response;
use yii\web\UnsupportedMediaTypeHttpException;
/**

4
framework/filters/Cors.php

@ -196,7 +196,7 @@ class Cors extends ActionFilter
if (in_array('*', $this->cors[$requestHeaderField])) {
$responseHeaders[$responseHeaderField] = $this->headerize($requestHeaders[$requestHeaderField]);
} else {
$requestedData = preg_split("/[\\s,]+/", $requestHeaders[$requestHeaderField], -1, PREG_SPLIT_NO_EMPTY);
$requestedData = preg_split('/[\\s,]+/', $requestHeaders[$requestHeaderField], -1, PREG_SPLIT_NO_EMPTY);
$acceptedData = array_uintersect($requestedData, $this->cors[$requestHeaderField], 'strcasecmp');
if (!empty($acceptedData)) {
$responseHeaders[$responseHeaderField] = implode(', ', $acceptedData);
@ -228,7 +228,7 @@ class Cors extends ActionFilter
*/
protected function headerize($string)
{
$headers = preg_split("/[\\s,]+/", $string, -1, PREG_SPLIT_NO_EMPTY);
$headers = preg_split('/[\\s,]+/', $string, -1, PREG_SPLIT_NO_EMPTY);
$headers = array_map(function ($element) {
return str_replace(' ', '-', ucwords(strtolower(str_replace(['_', '-'], [' ', ' '], $element))));
}, $headers);

2
framework/filters/HttpCache.php

@ -8,8 +8,8 @@
namespace yii\filters;
use Yii;
use yii\base\ActionFilter;
use yii\base\Action;
use yii\base\ActionFilter;
/**
* HttpCache implements client-side caching by utilizing the `Last-Modified` and `ETag` HTTP headers.

2
framework/filters/PageCache.php

@ -249,7 +249,7 @@ class PageCache extends ActionFilter
$data = [
'cacheVersion' => 1,
'cacheData' => is_array($beforeCacheResponseResult) ? $beforeCacheResponseResult : null,
'content' => ob_get_clean()
'content' => ob_get_clean(),
];
if ($data['content'] === false || $data['content'] === '') {
return;

4
framework/filters/auth/AuthInterface.php

@ -7,11 +7,11 @@
namespace yii\filters\auth;
use yii\web\User;
use yii\web\IdentityInterface;
use yii\web\Request;
use yii\web\Response;
use yii\web\IdentityInterface;
use yii\web\UnauthorizedHttpException;
use yii\web\User;
/**
* AuthInterface is the interface that should be implemented by auth method classes.

4
framework/filters/auth/AuthMethod.php

@ -10,10 +10,10 @@ namespace yii\filters\auth;
use Yii;
use yii\base\Action;
use yii\base\ActionFilter;
use yii\web\UnauthorizedHttpException;
use yii\web\User;
use yii\web\Request;
use yii\web\Response;
use yii\web\UnauthorizedHttpException;
use yii\web\User;
/**
* AuthMethod is a base class implementing the [[AuthInterface]] interface.

2
framework/filters/auth/CompositeAuth.php

@ -85,7 +85,7 @@ class CompositeAuth extends AuthMethod
public function challenge($response)
{
foreach ($this->authMethods as $method) {
/** @var $method AuthInterface */
/* @var $method AuthInterface */
$method->challenge($response);
}
}

4
framework/grid/DataColumn.php

@ -144,11 +144,11 @@ class DataColumn extends Column
if ($this->label === null) {
if ($provider instanceof ActiveDataProvider && $provider->query instanceof ActiveQueryInterface) {
/* @var $model Model */
$model = new $provider->query->modelClass;
$model = new $provider->query->modelClass();
$label = $model->getAttributeLabel($this->attribute);
} elseif ($provider instanceof ArrayDataProvider && $provider->modelClass !== null) {
/* @var $model Model */
$model = new $provider->modelClass;
$model = new $provider->modelClass();
$label = $model->getAttributeLabel($this->attribute);
} elseif ($this->grid->filterModel !== null && $this->grid->filterModel instanceof Model) {
$label = $this->grid->filterModel->getAttributeLabel($this->attribute);

8
framework/grid/GridView.php

@ -7,15 +7,15 @@
namespace yii\grid;
use Yii;
use Closure;
use yii\i18n\Formatter;
use Yii;
use yii\base\InvalidConfigException;
use yii\helpers\Url;
use yii\base\Model;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\helpers\Url;
use yii\i18n\Formatter;
use yii\widgets\BaseListView;
use yii\base\Model;
/**
* The GridView widget is used to display data in a grid.

1
framework/helpers/BaseConsole.php

@ -561,7 +561,6 @@ class BaseConsole
*
* @param string $string String to escape
*
* @access public
* @return string
*/
public static function escape($string)

10
framework/helpers/BaseFormatConverter.php

@ -152,7 +152,7 @@ class BaseFormatConverter
'MM' => 'm', // Numeric representation of a month, with leading zeros
'MMM' => 'M', // A short textual representation of a month, three letters
'MMMM' => 'F', // A full textual representation of a month, such as January or March
'MMMMM' => '', //
'MMMMM' => '',
'L' => 'n', // Stand alone month in year
'LL' => 'm', // Stand alone month in year
'LLL' => 'M', // Stand alone month in year
@ -205,7 +205,7 @@ class BaseFormatConverter
'z' => 'T', // Timezone abbreviation
'zz' => 'T', // Timezone abbreviation
'zzz' => 'T', // Timezone abbreviation
'zzzz' => 'T', // Timzone full name, not supported by php but we fallback
'zzzz' => 'T', // Timezone full name, not supported by php but we fallback
'Z' => 'O', // Difference to Greenwich time (GMT) in hours
'ZZ' => 'O', // Difference to Greenwich time (GMT) in hours
'ZZZ' => 'O', // Difference to Greenwich time (GMT) in hours
@ -362,7 +362,7 @@ class BaseFormatConverter
'MM' => 'mm', // Numeric representation of a month, with leading zeros
'MMM' => 'M', // A short textual representation of a month, three letters
'MMMM' => 'MM', // A full textual representation of a month, such as January or March
'MMMMM' => '', //
'MMMMM' => '',
'L' => 'm', // Stand alone month in year
'LL' => 'mm', // Stand alone month in year
'LLL' => 'M', // Stand alone month in year
@ -415,12 +415,12 @@ class BaseFormatConverter
'z' => '', // Timezone abbreviation
'zz' => '', // Timezone abbreviation
'zzz' => '', // Timezone abbreviation
'zzzz' => '', // Timzone full name, not supported by php but we fallback
'zzzz' => '', // Timezone full name, not supported by php but we fallback
'Z' => '', // Difference to Greenwich time (GMT) in hours
'ZZ' => '', // Difference to Greenwich time (GMT) in hours
'ZZZ' => '', // Difference to Greenwich time (GMT) in hours
'ZZZZ' => '', // Time Zone: long localized GMT (=OOOO) e.g. GMT-08:00
'ZZZZZ' => '', // TIme Zone: ISO8601 extended hms? (=XXXXX)
'ZZZZZ' => '', // Time Zone: ISO8601 extended hms? (=XXXXX)
'O' => '', // Time Zone: short localized GMT e.g. GMT-8
'OOOO' => '', // Time Zone: long localized GMT (=ZZZZ) e.g. GMT-08:00
'v' => '', // Time Zone: generic non-location (falls back first to VVVV and then to OOOO) using the ICU defined fallback here

2
framework/helpers/BaseHtml.php

@ -9,10 +9,10 @@ namespace yii\helpers;
use Yii;
use yii\base\InvalidParamException;
use yii\base\Model;
use yii\db\ActiveRecordInterface;
use yii\validators\StringValidator;
use yii\web\Request;
use yii\base\Model;
/**
* BaseHtml provides concrete implementation for [[Html]].

2
framework/helpers/BaseJson.php

@ -7,8 +7,8 @@
namespace yii\helpers;
use yii\base\InvalidParamException;
use yii\base\Arrayable;
use yii\base\InvalidParamException;
use yii\web\JsExpression;
/**

6
framework/i18n/DbMessageSource.php

@ -10,11 +10,11 @@ namespace yii\i18n;
use Yii;
use yii\base\InvalidConfigException;
use yii\caching\CacheInterface;
use yii\db\Connection;
use yii\db\Expression;
use yii\db\Query;
use yii\di\Instance;
use yii\helpers\ArrayHelper;
use yii\db\Connection;
use yii\db\Query;
/**
* DbMessageSource extends [[MessageSource]] and represents a message source that stores translated
@ -183,7 +183,7 @@ class DbMessageSource extends MessageSource
't1.category' => $category,
't2.language' => $fallbackLanguage,
])->andWhere([
'NOT IN', 't2.id', (new Query())->select('[[id]]')->from($this->messageTable)->where(['language' => $language])
'NOT IN', 't2.id', (new Query())->select('[[id]]')->from($this->messageTable)->where(['language' => $language]),
]);
}
}

4
framework/i18n/Formatter.php

@ -18,8 +18,8 @@ use yii\base\Component;
use yii\base\InvalidConfigException;
use yii\base\InvalidParamException;
use yii\helpers\FormatConverter;
use yii\helpers\HtmlPurifier;
use yii\helpers\Html;
use yii\helpers\HtmlPurifier;
/**
* Formatter provides a set of commonly used data formatting methods.
@ -705,7 +705,7 @@ class Formatter extends Component
return [
$timestamp,
!($info['hour'] === false && $info['minute'] === false && $info['second'] === false),
!($info['year'] === false && $info['month'] === false && $info['day'] === false)
!($info['year'] === false && $info['month'] === false && $info['day'] === false),
];
} else {
return new DateTime($value, new DateTimeZone($this->defaultTimeZone));

2
framework/i18n/GettextPoFile.php

@ -66,7 +66,7 @@ class GettextPoFile extends GettextFile
'"Language: ' . $language . '\n"',
'"MIME-Version: 1.0\n"',
'"Content-Type: text/plain; charset=' . Yii::$app->charset . '\n"',
'"Content-Transfer-Encoding: 8bit\n"'
'"Content-Transfer-Encoding: 8bit\n"',
];
$content = implode("\n", $headers) . "\n\n";
foreach ($messages as $id => $message) {

2
framework/log/DbTarget.php

@ -8,8 +8,8 @@
namespace yii\log;
use Yii;
use yii\db\Connection;
use yii\base\InvalidConfigException;
use yii\db\Connection;
use yii\di\Instance;
use yii\helpers\VarDumper;

6
framework/log/Logger.php

@ -279,9 +279,9 @@ class Logger extends Component
$memory = isset($log[5]) ? $log[5] : 0;
$log[6] = $i;
$hash = md5(serialize($token));
if ($level == Logger::LEVEL_PROFILE_BEGIN) {
if ($level == self::LEVEL_PROFILE_BEGIN) {
$stack[$hash] = $log;
} elseif ($level == Logger::LEVEL_PROFILE_END) {
} elseif ($level == self::LEVEL_PROFILE_END) {
if (isset($stack[$hash])) {
$timings[$stack[$hash][6]] = [
'info' => $stack[$hash][0],
@ -318,7 +318,7 @@ class Logger extends Component
self::LEVEL_TRACE => 'trace',
self::LEVEL_PROFILE_BEGIN => 'profile begin',
self::LEVEL_PROFILE_END => 'profile end',
self::LEVEL_PROFILE => 'profile'
self::LEVEL_PROFILE => 'profile',
];
return isset($levels[$level]) ? $levels[$level] : 'unknown';

2
framework/mail/BaseMessage.php

@ -7,9 +7,9 @@
namespace yii\mail;
use Yii;
use yii\base\ErrorHandler;
use yii\base\Object;
use Yii;
/**
* BaseMessage serves as a base class that implements the [[send()]] method required by [[MessageInterface]].

2
framework/mutex/DbMutex.php

@ -7,8 +7,8 @@
namespace yii\mutex;
use yii\db\Connection;
use yii\base\InvalidConfigException;
use yii\db\Connection;
use yii\di\Instance;
/**

6
framework/mutex/OracleMutex.php

@ -87,7 +87,7 @@ class OracleMutex extends DbMutex
$releaseOnCommit = $this->releaseOnCommit ? 'TRUE' : 'FALSE';
$timeout = abs((int) $timeout);
/** inside pl/sql scopes pdo binding not working correctly :( */
// inside pl/sql scopes pdo binding not working correctly :(
$this->db->createCommand(
'DECLARE
handle VARCHAR2(128);
@ -100,7 +100,7 @@ END;',
->bindParam(':lockStatus', $lockStatus, PDO::PARAM_INT, 1)
->execute();
return ($lockStatus === 0 || $lockStatus === '0');
return $lockStatus === 0 || $lockStatus === '0';
}
/**
@ -124,6 +124,6 @@ END;',
->bindParam(':result', $releaseStatus, PDO::PARAM_INT, 1)
->execute();
return ($releaseStatus === 0 || $releaseStatus === '0');
return $releaseStatus === 0 || $releaseStatus === '0';
}
}

47
framework/rbac/DbManager.php

@ -8,12 +8,12 @@
namespace yii\rbac;
use Yii;
use yii\base\InvalidCallException;
use yii\base\InvalidParamException;
use yii\caching\CacheInterface;
use yii\db\Connection;
use yii\db\Query;
use yii\db\Expression;
use yii\base\InvalidCallException;
use yii\base\InvalidParamException;
use yii\db\Query;
use yii\di\Instance;
/**
@ -204,7 +204,7 @@ class DbManager extends BaseManager
return true;
}
$query = new Query;
$query = new Query();
$parents = $query->select(['parent'])
->from($this->itemChildTable)
->where(['child' => $itemName])
@ -231,7 +231,7 @@ class DbManager extends BaseManager
return $this->items[$name];
}
$row = (new Query)->from($this->itemTable)
$row = (new Query())->from($this->itemTable)
->where(['name' => $name])
->one($this->db);
@ -415,7 +415,7 @@ class DbManager extends BaseManager
*/
protected function getItems($type)
{
$query = (new Query)
$query = (new Query())
->from($this->itemTable)
->where(['type' => $type]);
@ -460,7 +460,7 @@ class DbManager extends BaseManager
return [];
}
$query = (new Query)->select('b.*')
$query = (new Query())->select('b.*')
->from(['a' => $this->assignmentTable, 'b' => $this->itemTable])
->where('{{a}}.[[item_name]]={{b}}.[[name]]')
->andWhere(['a.user_id' => (string) $userId])
@ -507,7 +507,7 @@ class DbManager extends BaseManager
if (empty($result)) {
return [];
}
$query = (new Query)->from($this->itemTable)->where([
$query = (new Query())->from($this->itemTable)->where([
'type' => Item::TYPE_PERMISSION,
'name' => array_keys($result),
]);
@ -541,7 +541,7 @@ class DbManager extends BaseManager
*/
protected function getDirectPermissionsByUser($userId)
{
$query = (new Query)->select('b.*')
$query = (new Query())->select('b.*')
->from(['a' => $this->assignmentTable, 'b' => $this->itemTable])
->where('{{a}}.[[item_name]]={{b}}.[[name]]')
->andWhere(['a.user_id' => (string) $userId])
@ -562,7 +562,7 @@ class DbManager extends BaseManager
*/
protected function getInheritedPermissionsByUser($userId)
{
$query = (new Query)->select('item_name')
$query = (new Query())->select('item_name')
->from($this->assignmentTable)
->where(['user_id' => (string) $userId]);
@ -576,7 +576,7 @@ class DbManager extends BaseManager
return [];
}
$query = (new Query)->from($this->itemTable)->where([
$query = (new Query())->from($this->itemTable)->where([
'type' => Item::TYPE_PERMISSION,
'name' => array_keys($result),
]);
@ -594,7 +594,7 @@ class DbManager extends BaseManager
*/
protected function getChildrenList()
{
$query = (new Query)->from($this->itemChildTable);
$query = (new Query())->from($this->itemChildTable);
$parents = [];
foreach ($query->all($this->db) as $row) {
$parents[$row['parent']][] = $row['child'];
@ -627,7 +627,7 @@ class DbManager extends BaseManager
return isset($this->rules[$name]) ? $this->rules[$name] : null;
}
$row = (new Query)->select(['data'])
$row = (new Query())->select(['data'])
->from($this->ruleTable)
->where(['name' => $name])
->one($this->db);
@ -639,7 +639,6 @@ class DbManager extends BaseManager
$data = stream_get_contents($data);
}
return unserialize($data);
}
/**
@ -651,7 +650,7 @@ class DbManager extends BaseManager
return $this->rules;
}
$query = (new Query)->from($this->ruleTable);
$query = (new Query())->from($this->ruleTable);
$rules = [];
foreach ($query->all($this->db) as $row) {
@ -674,7 +673,7 @@ class DbManager extends BaseManager
return null;
}
$row = (new Query)->from($this->assignmentTable)
$row = (new Query())->from($this->assignmentTable)
->where(['user_id' => (string) $userId, 'item_name' => $roleName])
->one($this->db);
@ -698,7 +697,7 @@ class DbManager extends BaseManager
return [];
}
$query = (new Query)
$query = (new Query())
->from($this->assignmentTable)
->where(['user_id' => (string) $userId]);
@ -782,7 +781,7 @@ class DbManager extends BaseManager
*/
public function hasChild($parent, $child)
{
return (new Query)
return (new Query())
->from($this->itemChildTable)
->where(['parent' => $parent->name, 'child' => $child->name])
->one($this->db) !== false;
@ -793,7 +792,7 @@ class DbManager extends BaseManager
*/
public function getChildren($name)
{
$query = (new Query)
$query = (new Query())
->select(['name', 'type', 'description', 'rule_name', 'data', 'created_at', 'updated_at'])
->from([$this->itemTable, $this->itemChildTable])
->where(['parent' => $name, 'name' => new Expression('[[child]]')]);
@ -909,7 +908,7 @@ class DbManager extends BaseManager
protected function removeAllItems($type)
{
if (!$this->supportsCascadeUpdate()) {
$names = (new Query)
$names = (new Query())
->select(['name'])
->from($this->itemTable)
->where(['type' => $type])
@ -978,13 +977,13 @@ class DbManager extends BaseManager
return;
}
$query = (new Query)->from($this->itemTable);
$query = (new Query())->from($this->itemTable);
$this->items = [];
foreach ($query->all($this->db) as $row) {
$this->items[$row['name']] = $this->populateItem($row);
}
$query = (new Query)->from($this->ruleTable);
$query = (new Query())->from($this->ruleTable);
$this->rules = [];
foreach ($query->all($this->db) as $row) {
$data = $row['data'];
@ -994,7 +993,7 @@ class DbManager extends BaseManager
$this->rules[$row['name']] = unserialize($data);
}
$query = (new Query)->from($this->itemChildTable);
$query = (new Query())->from($this->itemChildTable);
$this->parents = [];
foreach ($query->all($this->db) as $row) {
if (isset($this->items[$row['child']])) {
@ -1018,7 +1017,7 @@ class DbManager extends BaseManager
return [];
}
return (new Query)->select('[[user_id]]')
return (new Query())->select('[[user_id]]')
->from($this->assignmentTable)
->where(['item_name' => $roleName])->column($this->db);
}

3
framework/rbac/PhpManager.php

@ -7,9 +7,9 @@
namespace yii\rbac;
use Yii;
use yii\base\InvalidCallException;
use yii\base\InvalidParamException;
use Yii;
use yii\helpers\VarDumper;
/**
@ -701,7 +701,6 @@ class PhpManager extends BaseManager
$this->saveItems();
return true;
}
/**

1
framework/rbac/Role.php

@ -8,7 +8,6 @@
namespace yii\rbac;
/**
*
* For more details and usage information on Role, see the [guide article on security authorization](guide:security-authorization).
*
* @author Qiang Xue <qiang.xue@gmail.com>

2
framework/rbac/migrations/m140506_102106_rbac_init.php

@ -74,7 +74,7 @@ class m140506_102106_rbac_init extends \yii\db\Migration
'updated_at' => $this->integer(),
'PRIMARY KEY ([[name]])',
'FOREIGN KEY ([[rule_name]]) REFERENCES ' . $authManager->ruleTable . ' ([[name]])' .
$this->buildFkClause('ON DELETE SET NULL', 'ON UPDATE CASCADE')
$this->buildFkClause('ON DELETE SET NULL', 'ON UPDATE CASCADE'),
], $tableOptions);
$this->createIndex('idx-auth_item-type', $authManager->itemTable, 'type');

10
framework/requirements/requirements.php

@ -1,10 +1,16 @@
<?php
/**
* These are the Yii core requirements for the [[YiiRequirementChecker]] instance.
* These requirements are mandatory for any Yii application.
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
/* @var $this YiiRequirementChecker */
/**
* These are the Yii core requirements for the [[YiiRequirementChecker]] instance.
* These requirements are mandatory for any Yii application.
*/
return array(
array(
'name' => 'PHP version',

6
framework/requirements/views/console/index.php

@ -1,4 +1,10 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
/* @var $this YiiRequirementChecker */
/* @var $summary array */
/* @var $requirements array[] */

2
framework/rest/Controller.php

@ -11,8 +11,8 @@ use Yii;
use yii\filters\auth\CompositeAuth;
use yii\filters\ContentNegotiator;
use yii\filters\RateLimiter;
use yii\web\Response;
use yii\filters\VerbFilter;
use yii\web\Response;
/**
* Controller is the base class for RESTful API controller classes.

2
framework/test/DbFixture.php

@ -8,9 +8,9 @@
namespace yii\test;
use Yii;
use yii\base\Object;
use yii\db\Connection;
use yii\di\Instance;
use yii\base\Object;
/**
* DbFixture is the base class for DB-related fixtures.

2
framework/validators/EachValidator.php

@ -7,8 +7,8 @@
namespace yii\validators;
use yii\base\InvalidConfigException;
use Yii;
use yii\base\InvalidConfigException;
use yii\base\Model;
/**

2
framework/validators/EmailValidator.php

@ -9,8 +9,8 @@ namespace yii\validators;
use Yii;
use yii\base\InvalidConfigException;
use yii\web\JsExpression;
use yii\helpers\Json;
use yii\web\JsExpression;
/**
* EmailValidator validates that the attribute value is a valid email address.

4
framework/validators/ExistValidator.php

@ -223,8 +223,8 @@ class ExistValidator extends Validator
foreach ($conditions as $columnName => $columnValue) {
$prefixedColumn = "{$alias}.[[" . preg_replace(
'/^' . preg_quote($alias) . '\.(.*)$/',
"$1",
$columnName) . "]]";
'$1',
$columnName) . ']]';
$prefixedConditions[$prefixedColumn] = $columnValue;
}
return $prefixedConditions;

3
framework/validators/FileValidator.php

@ -8,11 +8,11 @@
namespace yii\validators;
use Yii;
use yii\helpers\FileHelper;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\web\JsExpression;
use yii\web\UploadedFile;
use yii\helpers\FileHelper;
/**
* FileValidator verifies if an attribute is receiving a valid uploaded file.
@ -353,7 +353,6 @@ class FileValidator extends Validator
$extension = mb_strtolower($file->extension, 'UTF-8');
if ($this->checkExtensionByMimeType) {
$mimeType = FileHelper::getMimeType($file->tempName, null, false);
if ($mimeType === null) {
return false;

1
framework/validators/IpValidator.php

@ -71,7 +71,6 @@ class IpValidator extends Validator
* - `localhost`: `127.0.0.0/8', ::1`
* - `documentation`: `192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24, 2001:db8::/32`
* - `system`: `multicast, linklocal, localhost, documentation`
*
*/
public $networks = [
'*' => ['any'],

2
framework/validators/NumberValidator.php

@ -8,9 +8,9 @@
namespace yii\validators;
use Yii;
use yii\helpers\Json;
use yii\helpers\StringHelper;
use yii\web\JsExpression;
use yii\helpers\Json;
/**
* NumberValidator validates that the attribute value is a number.

2
framework/validators/RegularExpressionValidator.php

@ -10,8 +10,8 @@ namespace yii\validators;
use Yii;
use yii\base\InvalidConfigException;
use yii\helpers\Html;
use yii\web\JsExpression;
use yii\helpers\Json;
use yii\web\JsExpression;
/**
* RegularExpressionValidator validates that the attribute value matches the specified [[pattern]].

9
framework/validators/UniqueValidator.php

@ -10,8 +10,8 @@ namespace yii\validators;
use Yii;
use yii\base\Model;
use yii\db\ActiveQuery;
use yii\db\ActiveRecord;
use yii\db\ActiveQueryInterface;
use yii\db\ActiveRecord;
use yii\db\ActiveRecordInterface;
use yii\helpers\Inflector;
@ -75,7 +75,6 @@ class UniqueValidator extends Validator
*
* - `{attributes}`: the labels of the attributes being validated.
* - `{values}`: the values of the attributes being validated.
*
*/
public $message;
/**
@ -271,7 +270,7 @@ class UniqueValidator extends Validator
}
$this->addError($model, $attribute, $this->message, [
'attributes' => Inflector::sentence($attributeCombo),
'values' => implode('-', $valueCombo)
'values' => implode('-', $valueCombo),
]);
}
@ -291,8 +290,8 @@ class UniqueValidator extends Validator
foreach ($conditions as $columnName => $columnValue) {
$prefixedColumn = "{$alias}.[[" . preg_replace(
'/^' . preg_quote($alias) . '\.(.*)$/',
"$1",
$columnName) . "]]";
'$1',
$columnName) . ']]';
$prefixedConditions[$prefixedColumn] = $columnValue;
}
return $prefixedConditions;

2
framework/validators/UrlValidator.php

@ -9,8 +9,8 @@ namespace yii\validators;
use Yii;
use yii\base\InvalidConfigException;
use yii\web\JsExpression;
use yii\helpers\Json;
use yii\web\JsExpression;
/**
* UrlValidator validates that the attribute value is a valid http or https URL.

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save