Skip to content

Commit

Permalink
Merge pull request #92 from mirko-pagliai/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mirko-pagliai authored Oct 25, 2023
2 parents 79edf8f + 9af6fc4 commit 5f6c631
Show file tree
Hide file tree
Showing 17 changed files with 154 additions and 135 deletions.
21 changes: 12 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['7.4', '8.0', '8.1']
php-version: ['7.4', '8.0', '8.1', '8.2']
prefer-lowest: ['']
thumber-driver: ['imagick', 'gd']
include:
Expand All @@ -25,6 +25,9 @@ jobs:
- php-version: '8.1'
prefer-lowest: 'prefer-lowest'
thumber-driver: 'imagick'
- php-version: '8.2'
prefer-lowest: 'prefer-lowest'
thumber-driver: 'imagick'
- php-version: '7.4'
thumber-driver: 'gd'

Expand All @@ -42,7 +45,7 @@ jobs:

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
Expand Down Expand Up @@ -73,8 +76,8 @@ jobs:
fi
- name: Submit code coverage
if: matrix.php-version == '8.0'
uses: codecov/codecov-action@v2
if: matrix.php-version == '8.1'
uses: codecov/codecov-action@v3

cs-stan:
name: Coding Standard & Static Analysis
Expand All @@ -86,7 +89,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: '8.1'
coverage: none
tools: cs2pr

Expand All @@ -105,11 +108,11 @@ jobs:

- name: Run psalm
if: success() || failure()
run: vendor/bin/psalm.phar --output-format=github --php-version=8.0
run: vendor/bin/psalm --output-format=github --php-version=8.1

- name: Run phpstan
if: success() || failure()
run: vendor/bin/phpstan.phar analyse --error-format=github
run: vendor/bin/phpstan analyse --error-format=github


testsuite-windows:
Expand All @@ -133,7 +136,7 @@ jobs:

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
Expand All @@ -144,4 +147,4 @@ jobs:
run: composer update

- name: Run PHPUnit
run: vendor/bin/phpunit --verbose --exclude-group imageEquals
run: vendor/bin/phpunit --verbose --exclude-group imageEquals
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# 1.x branch
## 1.11 branch
### 1.11.2
* no longer needs the `me-tools` package;
* no longer uses the `Exceptionist` class;
* added tests for PHP 8.2.

### 1.11.1
* updated for `me-tools` 2.24.

Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
"ext-fileinfo": "*",
"cakephp/cakephp": "^4.4",
"intervention/image": "^2.4",
"mirko-pagliai/me-tools": "~2.23.1|~2.24",
"mirko-pagliai/php-thumber": "~1.5.3"
},
"require-dev": {
"cakephp/cakephp-codesniffer": "^4.0",
"phpunit/phpunit": "^9.1|^9.5",
"phpstan/phpstan": "^1.7",
"psalm/phar": "^4.24"
"phpstan/phpstan": "^1.10.38",
"vimeo/psalm": "^5.15.0"
},
"autoload": {
"psr-4": {
Expand Down
36 changes: 3 additions & 33 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,13 @@
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
autoloader="tests/bootstrap.php"
>
findUnusedBaselineEntry="true"
findUnusedCode="false">

<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<NullableReturnStatement>
<errorLevel type="suppress">
<file name="src/View/Helper/ThumbHelper.php" />
</errorLevel>
</NullableReturnStatement>

<RedundantPropertyInitializationCheck>
<errorLevel type="suppress">
<file name="src/Utility/ThumbCreator.php" />
</errorLevel>
</RedundantPropertyInitializationCheck>

<UndefinedConstant>
<errorLevel type="suppress">
<file name="src/Middleware/ThumbnailMiddleware.php" />
</errorLevel>
</UndefinedConstant>

<UndefinedFunction>
<errorLevel type="suppress">
<file name="src/View/Helper/ThumbHelper.php" />
</errorLevel>
</UndefinedFunction>

<UndefinedInterfaceMethod>
<errorLevel type="suppress">
<file name="src/Middleware/ThumbnailMiddleware.php" />
</errorLevel>
</UndefinedInterfaceMethod>
</issueHandlers>
</psalm>
29 changes: 11 additions & 18 deletions src/Command/ClearAllCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,18 @@
*/
namespace Thumber\Cake\Command;

use Cake\Command\Command;
use Cake\Console\Arguments;
use Cake\Console\ConsoleIo;
use Cake\Console\ConsoleOptionParser;
use Exception;
use MeTools\Command\Command;
use Thumber\Cake\Utility\ThumbManager;

/**
* Clears all thumbnails
*/
class ClearAllCommand extends Command
{
/**
* A `ThumbManager` instance
* @var \Thumber\Cake\Utility\ThumbManager
*/
public ThumbManager $ThumbManager;

/**
* Construct
*/
public function __construct()
{
parent::__construct();

$this->ThumbManager = new ThumbManager();
}

/**
* Hook method for defining this command's option parser
* @param \Cake\Console\ConsoleOptionParser $parser The parser to be defined
Expand All @@ -53,6 +37,15 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption
return $parser->setDescription(__d('thumber', 'Clears all thumbnails'));
}

/**
* Internal method to get a `ThumbManager` instance
* @return \Thumber\Cake\Utility\ThumbManager
*/
protected function getThumbManager(): ThumbManager
{
return new ThumbManager();
}

/**
* Clears all thumbnails
* @param \Cake\Console\Arguments $args The command arguments
Expand All @@ -62,7 +55,7 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption
public function execute(Arguments $args, ConsoleIo $io): void
{
try {
$count = $this->ThumbManager->clearAll();
$count = $this->getThumbManager()->clearAll();
} catch (Exception $e) {
$io->err(__d('thumber', 'Error deleting thumbnails'));
$this->abort();
Expand Down
29 changes: 11 additions & 18 deletions src/Command/ClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,18 @@
*/
namespace Thumber\Cake\Command;

use Cake\Command\Command;
use Cake\Console\Arguments;
use Cake\Console\ConsoleIo;
use Cake\Console\ConsoleOptionParser;
use Exception;
use MeTools\Command\Command;
use Thumber\Cake\Utility\ThumbManager;

/**
* Clears all thumbnails that have been generated from an image path
*/
class ClearCommand extends Command
{
/**
* A `ThumbManager` instance
* @var \Thumber\Cake\Utility\ThumbManager
*/
public ThumbManager $ThumbManager;

/**
* Construct
*/
public function __construct()
{
parent::__construct();

$this->ThumbManager = new ThumbManager();
}

/**
* Hook method for defining this command's option parser
* @param \Cake\Console\ConsoleOptionParser $parser The parser to be defined
Expand All @@ -57,6 +41,15 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption
]);
}

/**
* Internal method to get a `ThumbManager` instance
* @return \Thumber\Cake\Utility\ThumbManager
*/
protected function getThumbManager(): ThumbManager
{
return new ThumbManager();
}

/**
* Clears all thumbnails that have been generated from an image path
* @param \Cake\Console\Arguments $args The command arguments
Expand All @@ -66,7 +59,7 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption
public function execute(Arguments $args, ConsoleIo $io): void
{
try {
$count = $this->ThumbManager->clear((string)$args->getArgument('path'));
$count = $this->getThumbManager()->clear((string)$args->getArgument('path'));
} catch (Exception $e) {
$io->err(__d('thumber', 'Error deleting thumbnails'));
$this->abort();
Expand Down
20 changes: 13 additions & 7 deletions src/TestSuite/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
namespace Thumber\Cake\TestSuite;

use MeTools\TestSuite\TestCase as BaseTestCase;
use Cake\TestSuite\TestCase as BaseTestCase;
use Tools\Filesystem;

/**
Expand All @@ -25,13 +25,19 @@ abstract class TestCase extends BaseTestCase
use TestTrait;

/**
* Called after every test method
* @return void
* @throws \Symfony\Component\Filesystem\Exception\IOException
* @throws \Symfony\Component\Finder\Exception\DirectoryNotFoundException
* @throws \Tools\Exception\MethodNotExistsException
* @inheritDoc
*/
protected function tearDown(): void
public function setUp(): void
{
parent::setUp();

$this->loadPlugins(['Thumber\\Cake\\Plugin' => []]);
}

/**
* @inheritDoc
*/
public function tearDown(): void
{
Filesystem::instance()->unlinkRecursive(THUMBER_TARGET);

Expand Down
16 changes: 9 additions & 7 deletions src/Utility/ThumbCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
namespace Thumber\Cake\Utility;

use Cake\Routing\Router;
use LogicException;
use Thumber\ThumbCreator as BaseThumbCreator;
use Tools\Exceptionist;

/**
* Utility to create a thumb.
Expand All @@ -44,16 +44,18 @@ public function __construct(string $path)
* Builds and returns the url for the generated thumbnail
* @param bool $fullBase If `true`, the full base URL will be prepended to the result
* @return string
* @throws \ErrorException
* @throws \LogicException
* @since 1.5.1
*/
public function getUrl(bool $fullBase = true): string
{
Exceptionist::isTrue($this->target ?? false, __d(
'thumber',
'Missing path of the generated thumbnail. Probably the `{0}` method has not been invoked',
'save()'
));
if (empty($this->target)) {
throw new LogicException(__d(
'thumber',
'Missing path of the generated thumbnail. Probably the `{0}` method has not been invoked',
'save()'
));
}

return Router::url(['_name' => 'thumb', base64_encode(basename($this->target))], $fullBase);
}
Expand Down
15 changes: 10 additions & 5 deletions src/View/Helper/ThumbHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
namespace Thumber\Cake\View\Helper;

use Cake\View\Helper;
use LogicException;
use Thumber\Cake\Utility\ThumbCreator;
use Tools\Exceptionist;
use Tools\Exception\MethodNotExistsException;

/**
* Thumb Helper.
Expand Down Expand Up @@ -51,14 +52,17 @@ class ThumbHelper extends Helper
* @param string $method Method to invoke
* @param array $params Array of params for the method
* @return string
* @throws \ErrorException
* @throws \LogicException
* @throws \Tools\Exception\MethodNotExistsException
* @see https://github.com/mirko-pagliai/cakephp-thumber/wiki/How-to-use-the-helper
* @since 1.4.0
*/
public function __call(string $method, array $params): string
{
[$path, $params, $options] = $params + [null, [], []];
Exceptionist::isTrue($path, __d('thumber', 'Thumbnail path is missing'));
if (empty($path)) {
throw new LogicException(__d('thumber', 'Thumbnail path is missing'));
}
$url = $this->runUrlMethod($method, $path, $params, $options);

return $this->isUrlMethod($method) ? $url : $this->Html->image($url, $options);
Expand Down Expand Up @@ -86,7 +90,6 @@ protected function isUrlMethod(string $name): bool
* @param array $params Parameters for creating the thumbnail
* @param array $options Array of HTML attributes for the `img` element
* @return string Thumbnail url
* @throws \ErrorException
* @throws \Tools\Exception\MethodNotExistsException
* @since 1.4.0
*/
Expand All @@ -97,7 +100,9 @@ protected function runUrlMethod(string $name, string $path, array $params = [],
$options += ['fullBase' => true];

$className = ThumbCreator::class;
Exceptionist::methodExists($className, $name, __d('thumber', 'Method `{0}::{1}()` does not exist', $className, $name));
if (!method_exists($className, $name)) {
throw new MethodNotExistsException(__d('thumber', 'Method `{0}::{1}()` does not exist', $className, $name));
}
$Thumber = new $className($path);
$Thumber->$name($params['width'], $params['height'])->save($params);

Expand Down
Loading

0 comments on commit 5f6c631

Please sign in to comment.