Skip to content

Commit b8e423e

Browse files
Merge pull request #61 from mirko-pagliai/develop
Develop
2 parents 1a67266 + a63f237 commit b8e423e

29 files changed

+235
-133
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# 2.x branch
22
## 2.8 branch
3+
### 2.8.3
4+
* updated for `php-tools` 1.4.5;
5+
* added `phpstan`, so fixed some code.
6+
37
### 2.8.2
48
* updated for `php-tools` 1.4.1.
59

composer.json

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"require": {
1414
"php": ">=7.2",
1515
"cakephp/cakephp": "^4.0",
16-
"mirko-pagliai/php-tools": "^1.4.1"
16+
"mirko-pagliai/php-tools": "^1.4.5"
1717
},
1818
"require-dev": {
1919
"cakephp/cakephp-codesniffer": "^4.0",
@@ -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
}

config/bootstrap.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
use Cake\Core\Configure;
18+
use Tools\Filesystem;
1819

1920
//Sets the redirect to `/dev/null`. This string can be concatenated to shell commands
2021
if (!defined('REDIRECT_TO_DEV_NULL')) {
@@ -46,13 +47,12 @@
4647

4748
//Default target directory
4849
if (!Configure::check('DatabaseBackup.target')) {
49-
Configure::write('DatabaseBackup.target', ROOT . DS . 'backups');
50+
Configure::write('DatabaseBackup.target', (new Filesystem())->addSlashTerm(ROOT) . 'backups');
5051
}
5152

5253
//Checks for the target directory
5354
$target = Configure::read('DatabaseBackup.target');
54-
@mkdir($target);
55-
55+
@mkdir($target, 0777);
5656
if (!is_writeable($target)) {
5757
trigger_error(sprintf('Directory %s not writeable', $target), E_USER_ERROR);
5858
}

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/BackupTrait.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
use Cake\Datasource\ConnectionInterface;
2020
use Cake\Datasource\ConnectionManager;
2121
use InvalidArgumentException;
22-
use Symfony\Component\Filesystem\Filesystem;
2322
use Tools\Exceptionist;
23+
use Tools\Filesystem;
2424

2525
/**
2626
* A trait that provides some methods used by all other classes
@@ -41,8 +41,9 @@ trait BackupTrait
4141
*/
4242
public function getAbsolutePath(string $path): string
4343
{
44-
if (!(new Filesystem())->isAbsolutePath($path)) {
45-
return add_slash_term(Configure::read('DatabaseBackup.target')) . $path;
44+
$Filesystem = new Filesystem();
45+
if (!$Filesystem->isAbsolutePath($path)) {
46+
return $Filesystem->addSlashTerm(Configure::read('DatabaseBackup.target')) . $path;
4647
}
4748

4849
return $path;
@@ -88,11 +89,7 @@ public function getDriver(?ConnectionInterface $connection = null): object
8889
$connection = $connection ?: $this->getConnection();
8990
$className = get_class_short_name($connection->getDriver());
9091
$driver = App::classname(sprintf('%s.%s', 'DatabaseBackup', $className), 'Driver');
91-
Exceptionist::isTrue(
92-
$driver,
93-
__d('database_backup', 'The `{0}` driver does not exist', $className),
94-
InvalidArgumentException::class
95-
);
92+
Exceptionist::isTrue($driver, __d('database_backup', 'The `{0}` driver does not exist', $className), InvalidArgumentException::class);
9693

9794
return new $driver($connection);
9895
}
@@ -106,7 +103,7 @@ public function getDriver(?ConnectionInterface $connection = null): object
106103
*/
107104
public function getExtension(string $filename): ?string
108105
{
109-
$extension = get_extension($filename);
106+
$extension = (new Filesystem())->getExtension($filename);
110107

111108
return in_array($extension, array_keys(self::$validExtensions)) ? $extension : null;
112109
}

src/Command/DeleteAllCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
5757
}
5858

5959
foreach ($files as $file) {
60-
$io->verbose(__d('database_backup', 'Backup `{0}` has been deleted', rtr($file)));
60+
$io->verbose(__d('database_backup', 'Backup `{0}` has been deleted', $this->Filesystem->rtr($file)));
6161
}
6262

6363
$io->success(__d('database_backup', 'Deleted backup files: {0}', count($files)));

src/Command/ExportCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
9393

9494
//Exports
9595
$file = $instance->export();
96-
$io->success(__d('database_backup', 'Backup `{0}` has been exported', rtr($file)));
96+
$io->success(__d('database_backup', 'Backup `{0}` has been exported', $this->Filesystem->rtr($file)));
9797
$verbose = $args->getOption('verbose');
9898
$quiet = $args->getOption('quiet');
9999

100100
//Sends via email
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/ImportCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
5656

5757
try {
5858
$file = (new BackupImport())->filename($args->getArgument('filename'))->import();
59-
$io->success(__d('database_backup', 'Backup `{0}` has been imported', rtr($file)));
59+
$io->success(__d('database_backup', 'Backup `{0}` has been imported', $this->Filesystem->rtr($file)));
6060
} catch (Exception $e) {
6161
$io->error($e->getMessage());
6262
$this->abort();

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()));

0 commit comments

Comments
 (0)