Skip to content

Commit a63f237

Browse files
committed
added phpstan, so fixed some code
1 parent 8956aaf commit a63f237

File tree

14 files changed

+132
-18
lines changed

14 files changed

+132
-18
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# 2.x branch
22
## 2.8 branch
33
### 2.8.3
4-
* updated for `php-tools` 1.4.5.
4+
* updated for `php-tools` 1.4.5;
5+
* added `phpstan`, so fixed some code.
56

67
### 2.8.2
78
* updated for `php-tools` 1.4.1.

composer.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,28 @@
3131
"Cake\\Test\\": "vendor/cakephp/cakephp/tests",
3232
"DatabaseBackup\\Test\\": "tests"
3333
}
34+
},
35+
"scripts": {
36+
"check": [
37+
"@cs-check",
38+
"@update-lowest",
39+
"@test",
40+
"@composer update",
41+
"@test",
42+
"@stan-setup",
43+
"@stan"
44+
],
45+
"cs-check": "phpcs --standard=phpcs.xml.dist",
46+
"cs-fix": "phpcbf --standard=phpcs.xml.dist",
47+
"test": "phpunit",
48+
"test-coverage": "phpunit --coverage-html coverage",
49+
"phpstan": "phpstan.phar analyse",
50+
"psalm": "psalm.phar",
51+
"stan": [
52+
"@phpstan",
53+
"@psalm"
54+
],
55+
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:^0.12 psalm/phar:^3.18 && mv composer.backup composer.json",
56+
"update-lowest": "@composer update --prefer-lowest"
3457
}
3558
}

phpstan.neon

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
parameters:
2+
level: 6
3+
4+
paths:
5+
- config
6+
- src
7+
- tests
8+
9+
bootstrapFiles:
10+
- tests/bootstrap.php
11+
12+
checkGenericClassInNonGenericObjectType: false
13+
checkMissingIterableValueType: false
14+
treatPhpDocTypesAsCertain: false
15+
16+
excludes_analyse:
17+
- tests/test_app/
18+
19+
ignoreErrors:
20+
- '#(Ternary operator condition|Negated boolean expression) is always (true|false)\.$#'
21+
- "#^Constant REDIRECT_TO_DEV_NULL not found\\.$#"
22+
- "#^Static call to instance method Tools\\\\Exceptionist#"
23+
- "#^Parameter \\#2 \\$eventManager of method Cake\\\\TestSuite\\\\TestCase\\:\\:assertEventFired\\(\\) expects Cake\\\\Event\\\\EventManager\\|null, Cake\\\\Event\\\\EventManagerInterface given\\.$#"
24+
- "#^Parameter \\#1 \\$connection of method Cake\\\\Database\\\\Schema\\\\TableSchema\\:\\:dropSql\\(\\) expects Cake\\\\Database\\\\Connection, Cake\\\\Datasource\\\\ConnectionInterface given\\.$#"
25+
26+
-
27+
message: "#^Call to an undefined method Cake\\\\Datasource\\\\ConnectionInterface#"
28+
path: src/Driver/Sqlite.php
29+
30+
-
31+
message: "#^Unable to resolve the template type RealInstanceType#"
32+
path: src/TestSuite/TestCase.php
33+
34+
-
35+
message: '#has no return typehint specified\.$#'
36+
path: tests/TestCase
37+
38+
-
39+
message: "#^Binary operation \"\\+\" between#"
40+
count: 3
41+
path: tests/TestCase/Driver

psalm.xml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="4"
4+
resolveFromConfigFile="true"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xmlns="https://getpsalm.org/schema/config"
7+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
8+
autoloader="tests/bootstrap.php"
9+
>
10+
<projectFiles>
11+
<directory name="src" />
12+
<ignoreFiles>
13+
<directory name="vendor" />
14+
</ignoreFiles>
15+
</projectFiles>
16+
17+
<issueHandlers>
18+
<UndefinedConstant>
19+
<errorLevel type="suppress">
20+
<file name="src/Driver/Driver.php" />
21+
<file name="src/TestSuite/DriverTestCase.php" />
22+
</errorLevel>
23+
</UndefinedConstant>
24+
25+
<RedundantCondition>
26+
<errorLevel type="suppress">
27+
<file name="src/Driver/Mysql.php" />
28+
</errorLevel>
29+
</RedundantCondition>
30+
31+
<UndefinedInterfaceMethod>
32+
<errorLevel type="suppress">
33+
<file name="src/Driver/Sqlite.php" />
34+
</errorLevel>
35+
</UndefinedInterfaceMethod>
36+
37+
<UndefinedClass>
38+
<errorLevel type="suppress">
39+
<file name="src/BackupTrait.php" />
40+
</errorLevel>
41+
</UndefinedClass>
42+
43+
<InvalidArgument>
44+
<errorLevel type="suppress">
45+
<file name="src/Driver/Sqlite.php" />
46+
</errorLevel>
47+
</InvalidArgument>
48+
</issueHandlers>
49+
</psalm>

src/Command/ExportCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
101101
if ($args->getOption('send')) {
102102
$SendCommand = new SendCommand();
103103
$SendCommand->execute(new Arguments(
104-
[$file, $args->getOption('send')],
104+
[$file, (string)$args->getOption('send')],
105105
compact('verbose', 'quiet'),
106106
$SendCommand->getOptionParser()->argumentNames()
107107
), $io);
@@ -111,7 +111,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
111111
if ($args->getOption('rotate')) {
112112
$RotateCommand = new RotateCommand();
113113
$RotateCommand->execute(new Arguments(
114-
[$args->getOption('rotate')],
114+
[(string)$args->getOption('rotate')],
115115
compact('verbose', 'quiet'),
116116
$RotateCommand->getOptionParser()->argumentNames()
117117
), $io);

src/Command/IndexCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
6666
__d('database_backup', 'Datetime'),
6767
];
6868
$cells = $backups->map(function (Entity $backup) {
69-
return $backup->set('compression', $backup->compression ?: '')
70-
->set('datetime', $backup->datetime->nice())
71-
->set('size', Number::toReadableSize($backup->size))
69+
return $backup->set('compression', $backup->get('compression') ?: '')
70+
->set('datetime', $backup->get('datetime')->nice())
71+
->set('size', Number::toReadableSize($backup->get('size')))
7272
->toArray();
7373
});
7474
$io->helper('table')->output(array_merge([$headers], $cells->toList()));

src/Driver/Mysql.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected function writeAuthFile(string $content): bool
7676
{
7777
$content = str_replace(
7878
['{{USER}}', '{{PASSWORD}}', '{{HOST}}'],
79-
[$this->getConfig('username'), $this->getConfig('password'), $this->getConfig('host')],
79+
[(string)$this->getConfig('username'), (string)$this->getConfig('password'), (string)$this->getConfig('host')],
8080
$content
8181
);
8282

src/TestSuite/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ protected function createSomeBackups(): array
9191
* Internal method to mock a driver
9292
* @param string $className Driver class name
9393
* @param array $methods The list of methods to mock
94-
* @return \DatabaseBackup\Driver\Driver|\PHPUnit_Framework_MockObject_MockObject
94+
* @return \DatabaseBackup\Driver\Driver|\PHPUnit\Framework\MockObject\MockObject
9595
*/
9696
protected function getMockForDriver($className, array $methods)
9797
{

src/Utility/BackupManager.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
namespace DatabaseBackup\Utility;
1717

18-
use Cake\Collection\Collection;
18+
use Cake\Collection\CollectionInterface;
1919
use Cake\Core\Configure;
2020
use Cake\I18n\FrozenTime;
2121
use Cake\Mailer\Email;
@@ -66,11 +66,11 @@ public function deleteAll(): array
6666

6767
/**
6868
* Returns a list of database backups
69-
* @return \Cake\Collection\Collection Collection of backups. Each backup
69+
* @return \Cake\Collection\CollectionInterface Collection of backups. Each backup
7070
* is an entity
7171
* @see https://github.com/mirko-pagliai/cakephp-database-backup/wiki/How-to-use-the-BackupManager-utility#index
7272
*/
73-
public function index(): Collection
73+
public function index(): CollectionInterface
7474
{
7575
$finder = (new Finder())->files()->name('/\.sql(\.(gz|bz2))?$/')->in(Configure::read('DatabaseBackup.target'));
7676

tests/TestCase/Driver/MysqlTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
class MysqlTest extends DriverTestCase
2424
{
2525
/**
26-
* @var \DatabaseBackup\Driver\Mysql
26+
* @var string
2727
*/
2828
protected $DriverClass = Mysql::class;
2929

@@ -92,7 +92,7 @@ public function testAfterExport()
9292
{
9393
$driver = $this->getMockForDriver(Mysql::class, ['deleteAuthFile']);
9494
$driver->expects($this->once())->method('deleteAuthFile');
95-
$this->assertNull($driver->afterExport());
95+
$driver->afterExport();
9696
}
9797

9898
/**
@@ -103,7 +103,7 @@ public function testAfterImport()
103103
{
104104
$driver = $this->getMockForDriver(Mysql::class, ['deleteAuthFile']);
105105
$driver->expects($this->once())->method('deleteAuthFile');
106-
$this->assertNull($driver->afterImport());
106+
$driver->afterImport();
107107
}
108108

109109
/**

0 commit comments

Comments
 (0)