Browse Source

Fix errors reported by phpstan.

ADmad 9 years ago
parent
commit
2e1a26694e

+ 1 - 0
src/Controller/Component/PaginatorComponent.php

@@ -165,6 +165,7 @@ class PaginatorComponent extends Component
      */
     public function paginate($object, array $settings = [])
     {
+        $query = null;
         if ($object instanceof QueryInterface) {
             $query = $object;
             $object = $query->repository();

+ 1 - 0
src/Database/Schema/MysqlSchema.php

@@ -483,6 +483,7 @@ class MysqlSchema extends BaseSchema
     public function indexSql(TableSchema $schema, $name)
     {
         $data = $schema->index($name);
+        $out = '';
         if ($data['type'] === Table::INDEX_INDEX) {
             $out = 'KEY ';
         }

+ 1 - 0
src/Database/Schema/SqliteSchema.php

@@ -366,6 +366,7 @@ class SqliteSchema extends BaseSchema
             return '';
         }
         $clause = '';
+        $type = '';
         if ($data['type'] === TableSchema::CONSTRAINT_PRIMARY) {
             $type = 'PRIMARY KEY';
         }

+ 1 - 0
src/Datasource/EntityTrait.php

@@ -985,6 +985,7 @@ trait EntityTrait
         while ($len) {
             $part = array_shift($path);
             $len = count($path);
+            $val = null;
             if ($entity instanceof EntityInterface) {
                 $val = $entity->get($part);
             } elseif (is_array($entity)) {

+ 1 - 0
src/Error/ExceptionRenderer.php

@@ -118,6 +118,7 @@ class ExceptionRenderer implements ExceptionRendererInterface
             $request = ServerRequest::createFromGlobals();
         }
         $response = new Response();
+        $controller = null;
 
         try {
             $class = App::className('Error', 'Controller', 'Controller');

+ 1 - 0
src/Http/Client/Auth/Digest.php

@@ -117,6 +117,7 @@ class Digest
         $path = $request->getUri()->getPath();
         $a1 = md5($credentials['username'] . ':' . $credentials['realm'] . ':' . $credentials['password']);
         $a2 = md5($request->method() . ':' . $path);
+        $nc = null;
 
         if (empty($credentials['qop'])) {
             $response = md5($a1 . ':' . $credentials['nonce'] . ':' . $a2);

+ 1 - 10
src/Http/Client/Auth/Oauth.php

@@ -257,16 +257,7 @@ class Oauth
      */
     protected function _normalizedUrl($uri)
     {
-        $scheme = $uri->getScheme();
-        $defaultPorts = [
-            'http' => 80,
-            'https' => 443
-        ];
-        $port = $uri->getPort();
-        if ($port && $port != $defaultPorts[$scheme]) {
-            $parts['host'] .= ':' . $port;
-        }
-        $out = $scheme . '://';
+        $out = $uri->getScheme() . '://';
         $out .= strtolower($uri->getHost());
         $out .= $uri->getPath();
 

+ 2 - 0
src/Http/MiddlewareQueue.php

@@ -164,6 +164,7 @@ class MiddlewareQueue implements Countable
     public function insertBefore($class, $middleware)
     {
         $found = false;
+        $i = null;
         foreach ($this->queue as $i => $object) {
             if ((is_string($object) && $object === $class)
                 || is_a($object, $class)
@@ -192,6 +193,7 @@ class MiddlewareQueue implements Countable
     public function insertAfter($class, $middleware)
     {
         $found = false;
+        $i = null;
         foreach ($this->queue as $i => $object) {
             if ((is_string($object) && $object === $class)
                 || is_a($object, $class)

+ 3 - 1
src/Network/Socket.php

@@ -323,11 +323,13 @@ class Socket
             }
         }
         $totalBytes = strlen($data);
-        for ($written = 0; $written < $totalBytes; $written += $rv) {
+        $written = 0;
+        while ($written < $totalBytes) {
             $rv = fwrite($this->connection, substr($data, $written));
             if ($rv === false || $rv === 0) {
                 return $written;
             }
+            $written += $rv;
         }
 
         return $written;

+ 1 - 0
src/ORM/Association/BelongsToMany.php

@@ -432,6 +432,7 @@ class BelongsToMany extends Association
         $cond = $belongsTo->_joinCondition(['foreignKey' => $belongsTo->getForeignKey()]);
         $cond += $this->junctionConditions();
 
+        $includeFields = null;
         if (isset($options['includeFields'])) {
             $includeFields = $options['includeFields'];
         }

+ 1 - 0
src/ORM/Behavior/TranslateBehavior.php

@@ -607,6 +607,7 @@ class TranslateBehavior extends Behavior implements PropertyMarshalInterface
         $primaryKey = (array)$this->_table->getPrimaryKey();
         $key = $entity->get(current($primaryKey));
         $find = [];
+        $contents = [];
 
         foreach ($translations as $lang => $translation) {
             foreach ($fields as $field) {

+ 1 - 0
src/Shell/RoutesShell.php

@@ -53,6 +53,7 @@ class RoutesShell extends Shell
     {
         try {
             $route = Router::parse($url);
+            $name = null;
             foreach (Router::routes() as $r) {
                 if ($r->match($route)) {
                     $name = isset($r->options['_name']) ? $r->options['_name'] : $r->getName();

+ 1 - 0
src/Shell/Task/ExtractTask.php

@@ -439,6 +439,7 @@ class ExtractTask extends Shell
                 $strings = $this->_getStrings($position, $mapCount);
 
                 if ($mapCount === count($strings)) {
+                    $singular = null;
                     extract(array_combine($map, $strings));
                     $domain = isset($domain) ? $domain : 'default';
                     $details = [

+ 2 - 0
src/TestSuite/TestCase.php

@@ -485,6 +485,7 @@ abstract class TestCase extends BaseTestCase
             }
 
             list($description, $expressions, $itemNum) = $assertion;
+            $expression = null;
             foreach ((array)$expressions as $expression) {
                 $expression = sprintf('/^%s/s', $expression);
                 if (preg_match($expression, $string, $match)) {
@@ -524,6 +525,7 @@ abstract class TestCase extends BaseTestCase
         $explains = $assertions['explains'];
         do {
             $matches = false;
+            $j = null;
             foreach ($asserts as $j => $assert) {
                 if (preg_match(sprintf('/^%s/s', $assert), $string, $match)) {
                     $matches = true;

+ 3 - 0
src/Utility/Hash.php

@@ -464,6 +464,7 @@ class Hash
             return [];
         }
 
+        $vals = null;
         if (!empty($valuePath) && is_array($valuePath)) {
             $format = array_shift($valuePath);
             $vals = static::format($data, $valuePath, $format);
@@ -484,6 +485,7 @@ class Hash
             $group = static::extract($data, $groupPath);
             if (!empty($group)) {
                 $c = count($keys);
+                $out = [];
                 for ($i = 0; $i < $c; $i++) {
                     if (!isset($group[$i])) {
                         $group[$i] = 0;
@@ -742,6 +744,7 @@ class Hash
     {
         $args = array_slice(func_get_args(), 1);
         $return = $data;
+        $stack = [];
 
         foreach ($args as &$curArg) {
             $stack[] = [(array)$curArg, &$return];

+ 2 - 0
src/Utility/Text.php

@@ -478,6 +478,7 @@ class Text
             'limit' => -1,
         ];
         $options += $defaults;
+        $html = $format = $ellipsis = $exact = $limit = null;
         extract($options);
 
         if (is_array($phrase)) {
@@ -546,6 +547,7 @@ class Text
             'ellipsis' => '...', 'exact' => true
         ];
         $options += $default;
+        $exact = $ellipsis = null;
         extract($options);
 
         if (mb_strlen($text) <= $length) {

+ 1 - 0
src/Utility/Xml.php

@@ -328,6 +328,7 @@ class Xml
      */
     protected static function _createChild($data)
     {
+        $value = $dom = $key = $format = $node = null;
         extract($data);
         $childNS = $childValue = null;
         if (is_object($value) && method_exists($value, 'toArray') && is_callable([$value, 'toArray'])) {

+ 3 - 1
src/View/Helper/PaginatorHelper.php

@@ -869,13 +869,15 @@ class PaginatorHelper extends Helper
         ]);
 
         $start = $params['page'] + 1;
-        for ($i = $start; $i < $end; $i++) {
+        $i = $start;
+        while ($i < $end) {
             $out .= $this->_formatNumber($templater, [
                 'text' => $this->Number->format($i),
                 'page' => $i,
                 'model' => $options['model'],
                 'url' => $options['url'],
             ]);
+            $i++;
         }
 
         if ($end != $params['page']) {

+ 1 - 0
src/View/Helper/RssHelper.php

@@ -210,6 +210,7 @@ class RssHelper extends Helper
                     break;
                 case 'category':
                     if (is_array($val) && !empty($val[0])) {
+                        $categories = [];
                         foreach ($val as $category) {
                             $attrib = [];
                             if (is_array($category) && isset($category['domain'])) {

+ 1 - 0
src/View/View.php

@@ -583,6 +583,7 @@ class View implements EventDispatcherInterface
             return null;
         }
 
+        $defaultLayout = null;
         if ($layout !== null) {
             $defaultLayout = $this->layout;
             $this->layout = $layout;