From 67f67e3a69e14935bc3f0b1c90e41e83df0adebc Mon Sep 17 00:00:00 2001 From: Vladimir Reznichenko Date: Mon, 29 Jan 2018 11:08:57 +0100 Subject: [PATCH] SCA with Php Inspections (EA Extended) (#15571) --- build/controllers/PhpDocController.php | 6 +++--- build/controllers/ReleaseController.php | 4 ++-- tests/data/validators/models/FakedValidationModel.php | 4 ++-- tests/framework/db/ActiveRecordTest.php | 2 +- tests/framework/db/CommandTest.php | 2 +- tests/framework/db/mysql/connection/DeadLockTest.php | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build/controllers/PhpDocController.php b/build/controllers/PhpDocController.php index 2757c79..4abed4c 100644 --- a/build/controllers/PhpDocController.php +++ b/build/controllers/PhpDocController.php @@ -176,7 +176,7 @@ class PhpDocController extends Controller $this->setUpExtensionAliases($extensionPath); list(, $extension) = $matches; - Yii::setAlias("@yii/$extension", "$root"); + Yii::setAlias("@yii/$extension", (string)$root); if (is_file($autoloadFile = Yii::getAlias("@yii/$extension/vendor/autoload.php"))) { include $autoloadFile; } @@ -199,7 +199,7 @@ class PhpDocController extends Controller $this->setUpExtensionAliases($extensionPath); list(, $appName) = $matches; - Yii::setAlias("@app-$appName", "$root"); + Yii::setAlias("@app-$appName", (string)$root); if (is_file($autoloadFile = Yii::getAlias("@app-$appName/vendor/autoload.php"))) { include $autoloadFile; } @@ -688,7 +688,7 @@ class PhpDocController extends Controller $docline = ' * @'; $docline .= 'property'; // Do not use property-read and property-write as few IDEs support complex syntax. $note = ''; - if (isset($prop['get']) && isset($prop['set'])) { + if (isset($prop['get'], $prop['set'])) { if ($prop['get']['type'] != $prop['set']['type']) { $note = ' Note that the type of this property differs in getter and setter.' . ' See [[get' . ucfirst($propName) . '()]] and [[set' . ucfirst($propName) . '()]] for details.'; diff --git a/build/controllers/ReleaseController.php b/build/controllers/ReleaseController.php index 582e7cc..4448964 100644 --- a/build/controllers/ReleaseController.php +++ b/build/controllers/ReleaseController.php @@ -109,7 +109,7 @@ class ReleaseController extends Controller foreach ($items as $item) { $this->stdout("fetching tags for $item..."); if ($item === 'framework') { - $this->gitFetchTags("{$this->basePath}"); + $this->gitFetchTags((string)$this->basePath); } elseif (strncmp('app-', $item, 4) === 0) { $this->gitFetchTags("{$this->basePath}/apps/" . substr($item, 4)); } else { @@ -874,7 +874,7 @@ class ReleaseController extends Controller $state = 'end'; } // add continued lines to the last item to keep them together - if (!empty(${$state}) && trim($line !== '') && strpos($line, '- ') !== 0) { + if (!empty(${$state}) && trim($line) !== '' && strncmp($line, '- ', 2) !== 0) { end(${$state}); ${$state}[key(${$state})] .= "\n" . $line; } else { diff --git a/tests/data/validators/models/FakedValidationModel.php b/tests/data/validators/models/FakedValidationModel.php index fd18f36..2bbc9d9 100644 --- a/tests/data/validators/models/FakedValidationModel.php +++ b/tests/data/validators/models/FakedValidationModel.php @@ -58,7 +58,7 @@ class FakedValidationModel extends Model public function __get($name) { - if (stripos($name, 'attr') === 0) { + if (strncasecmp($name, 'attr', 4) === 0) { return isset($this->attr[$name]) ? $this->attr[$name] : null; } @@ -67,7 +67,7 @@ class FakedValidationModel extends Model public function __set($name, $value) { - if (stripos($name, 'attr') === 0) { + if (strncasecmp($name, 'attr', 4) === 0) { $this->attr[$name] = $value; } else { parent::__set($name, $value); diff --git a/tests/framework/db/ActiveRecordTest.php b/tests/framework/db/ActiveRecordTest.php index 3756453..e5dfd50 100644 --- a/tests/framework/db/ActiveRecordTest.php +++ b/tests/framework/db/ActiveRecordTest.php @@ -744,7 +744,7 @@ abstract class ActiveRecordTest extends DatabaseTestCase // join with ON condition and alias in relation definition if ($aliasMethod === 'explicit' || $aliasMethod === 'querysyntax') { $relationName = 'books' . ucfirst($aliasMethod) . 'A'; - $orders = Order::find()->joinWith(["$relationName"])->orderBy('order.id')->all(); + $orders = Order::find()->joinWith([(string)$relationName])->orderBy('order.id')->all(); $this->assertCount(3, $orders); $this->assertEquals(1, $orders[0]->id); $this->assertEquals(2, $orders[1]->id); diff --git a/tests/framework/db/CommandTest.php b/tests/framework/db/CommandTest.php index 9ea54ad..24becf4 100644 --- a/tests/framework/db/CommandTest.php +++ b/tests/framework/db/CommandTest.php @@ -307,7 +307,7 @@ SQL; public function testBatchInsertWithYield() { - if (version_compare(PHP_VERSION, '5.5', '<')) { + if (PHP_VERSION_ID < 50500) { $this->markTestSkipped('The yield function is only supported with php 5.5 =< version'); } else { include __DIR__ . '/testBatchInsertWithYield.php'; diff --git a/tests/framework/db/mysql/connection/DeadLockTest.php b/tests/framework/db/mysql/connection/DeadLockTest.php index 9f54a06..1ade75c 100644 --- a/tests/framework/db/mysql/connection/DeadLockTest.php +++ b/tests/framework/db/mysql/connection/DeadLockTest.php @@ -31,7 +31,7 @@ class DeadLockTest extends \yiiunit\framework\db\mysql\ConnectionTest */ public function testDeadlockException() { - if (getenv('TRAVIS') && version_compare(PHP_VERSION, '7.0.0', '<')) { + if (getenv('TRAVIS') && PHP_VERSION_ID < 70000) { $this->markTestSkipped('Skipping PHP 5 on Travis since it segfaults with pcntl'); } @@ -272,7 +272,7 @@ class DeadLockTest extends \yiiunit\framework\db\mysql\ConnectionTest */ private function setErrorHandler() { - if (version_compare(PHP_VERSION, '7', '<')) { + if (PHP_VERSION_ID < 70000) { set_error_handler(function ($errno, $errstr, $errfile, $errline) { throw new \ErrorException($errstr, $errno, $errno, $errfile, $errline); });