Skip to content

Commit 9981890

Browse files
authored
Merge pull request #84 from UseMuffin/static-analysis
Fix errors reported by phpstan.
2 parents 74fce15 + e83f6d9 commit 9981890

File tree

7 files changed

+29
-17
lines changed

7 files changed

+29
-17
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ matrix:
2525
- php: 7.0
2626
env: PHPCS=1 DEFAULT=0
2727

28-
- php: 7.0
28+
- php: 7.1
2929
env: PHPSTAN=1 DEFAULT=0
3030

3131
- php: 5.6
@@ -34,7 +34,7 @@ matrix:
3434
before_script:
3535
- if [[ $TRAVIS_PHP_VERSION != 7.0 ]]; then phpenv config-rm xdebug.ini; fi
3636

37-
- if [[ $PHPSTAN = 1 ]]; then composer require --dev phpstan/phpstan:^0.9; fi
37+
- if [[ $PHPSTAN = 1 ]]; then composer require --dev phpstan/phpstan:^0.11; fi
3838
- if [[ $PHPSTAN != 1 ]]; then composer install --no-interaction; fi
3939

4040
script:
@@ -43,7 +43,7 @@ script:
4343

4444
- if [[ $PHPCS = 1 ]]; then ./vendor/bin/phpcs -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi
4545

46-
- if [[ $PHPSTAN = 1 ]]; then vendor/bin/phpstan analyse -l 2 src; fi
46+
- if [[ $PHPSTAN = 1 ]]; then vendor/bin/phpstan analyse src; fi
4747

4848
after_success:
4949
- if [[ $CODECOVERAGE = 1 ]]; then bash <(curl -s https://codecov.io/bash); fi

phpstan.neon

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
parameters:
2+
level: 4
3+
ignoreErrors:
4+
- '#Method Muffin\\Webservice\\Query::endpoint\(\) should return \$this\(Muffin\\Webservice\\Query\)|Muffin\\Webservice\\Model\\Endpoint but returns Cake\Datasource\RepositoryInterface#'
5+
- '#Call to an undefined method Cake\\Datasource\\RepositoryInterface::callFinder\(\)#'
6+
- '#Call to an undefined method Cake\\Datasource\\RepositoryInterface::dispatchEvent\(\)#'
7+
- '#Method Muffin\\Webservice\\Query::offset\(\) should return \$this\(Cake\\Datasource\\QueryInterface\) but returns \$this\(Muffin\\Webservice\\Query\)#'
8+
- '#Return type \(array\) of method Muffin\\Webservice\\Query::aliasField\(\) should be compatible with return type \(string\) of method Cake\\Datasource\\QueryInterface::aliasField\(\)#'
9+
- '#Call to an undefined method Cake\\Datasource\\RepositoryInterface::getName\(\)#'
10+
- '#Call to an undefined method Traversable::count\(\)#'
11+
- '#Strict comparison using === between string and null will always evaluate to false#'
12+
- '#Negated boolean expression is always false#'

src/AbstractDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function logger()
165165
/**
166166
* Returns a logger instance
167167
*
168-
* @return \Psr\Log\LoggerInterface
168+
* @return \Psr\Log\LoggerInterface|null
169169
*/
170170
public function getLogger()
171171
{

src/Model/Endpoint.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class Endpoint implements RepositoryInterface, EventListenerInterface, EventDisp
5050
/**
5151
* Connection instance this endpoint uses
5252
*
53-
* @var \Muffin\Webservice\Connection $connection Connection instance
53+
* @var \Muffin\Webservice\Connection|null $connection Connection instance
5454
*/
5555
protected $_connection;
5656

@@ -222,7 +222,7 @@ public function initialize(array $config)
222222
public function endpoint($endpoint = null)
223223
{
224224
if ($endpoint !== null) {
225-
return $this->setName($endpoint);
225+
$this->setName($endpoint);
226226
}
227227

228228
return $this->getName();
@@ -362,7 +362,7 @@ public function setConnection($connection)
362362
/**
363363
* Returns the connection driver.
364364
*
365-
* @return \Muffin\Webservice\Connection
365+
* @return \Muffin\Webservice\Connection|null
366366
*/
367367
public function getConnection()
368368
{
@@ -592,7 +592,7 @@ public function getDisplayField()
592592
public function resourceClass($name = null)
593593
{
594594
if ($name !== null) {
595-
return $this->setResourceClass($name);
595+
$this->setResourceClass($name);
596596
}
597597

598598
return $this->getResourceClass();
@@ -654,7 +654,7 @@ public function getResourceClass()
654654
public function inflectionMethod($method = null)
655655
{
656656
if ($method !== null) {
657-
return $this->setInflectionMethod($method);
657+
$this->setInflectionMethod($method);
658658
}
659659

660660
return $this->getInflectionMethod();
@@ -1057,7 +1057,7 @@ public function exists($conditions)
10571057
*/
10581058
public function save(EntityInterface $resource, $options = [])
10591059
{
1060-
$options = new ArrayObject($options + [
1060+
$options = new ArrayObject((array)$options + [
10611061
'checkRules' => true,
10621062
'checkExisting' => false,
10631063
]);

src/Query.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class Query implements IteratorAggregate, JsonSerializable, QueryInterface
8181
/**
8282
* The results from the webservice
8383
*
84-
* @var ResultSet
84+
* @var ResultSet|null
8585
*/
8686
protected $__resultSet;
8787

@@ -234,7 +234,7 @@ public function firstOrFail()
234234
}
235235
throw new RecordNotFoundException(sprintf(
236236
'Record not found in endpoint "%s"',
237-
$this->getRepository()->endpoint()
237+
$this->getRepository()->getName()
238238
));
239239
}
240240

src/ResultSet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class ResultSet implements ResultSetInterface
4646
*/
4747
public function __construct(array $resources, $total = null)
4848
{
49-
$this->_results = \SplFixedArray::fromArray($resources, false);
49+
$this->_results = array_values($resources);
5050
$this->_total = $total;
5151
}
5252

src/Webservice/Webservice.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ abstract class Webservice implements WebserviceInterface
2323
/**
2424
* The driver to use to communicate with the webservice
2525
*
26-
* @var \Muffin\Webservice\AbstractDriver
26+
* @var \Muffin\Webservice\AbstractDriver|null
2727
*/
2828
protected $_driver;
2929

@@ -99,7 +99,7 @@ public function setDriver(AbstractDriver $driver)
9999
/**
100100
* Get this webservices driver
101101
*
102-
* @return \Muffin\Webservice\AbstractDriver
102+
* @return \Muffin\Webservice\AbstractDriver|null
103103
*/
104104
public function getDriver()
105105
{
@@ -195,8 +195,8 @@ public function execute(Query $query, array $options = [])
195195
}
196196

197197
// Write to the logger when one has been defined
198-
if ($this->getDriver()->logger()) {
199-
$this->_logQuery($query, $this->getDriver()->logger());
198+
if ($this->getDriver()->getLogger()) {
199+
$this->_logQuery($query, $this->getDriver()->getLogger());
200200
}
201201

202202
return $result;

0 commit comments

Comments
 (0)