Skip to content

Commit

Permalink
Merge pull request #100 from prestaconcept/release/v4.0
Browse files Browse the repository at this point in the history
Release/v4.0
  • Loading branch information
J-Ben87 authored Jan 4, 2024
2 parents 83b6748 + 6e66620 commit 53d41a7
Show file tree
Hide file tree
Showing 17 changed files with 101 additions and 56 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
name: 'Quality'

on:
push:
branches: ['*']
push

jobs:
phpcs:
name: 'PHP CodeSniffer'
ecs:
name: 'Easy Coding Standard'
runs-on: 'ubuntu-latest'
env:
SYMFONY_REQUIRE: '${{matrix.symfony-require}}'

strategy:
matrix:
php-version: ['7.4', '8.0', '8.1', '8.2']
symfony-require: ['5.4.*', '6.0.*', '6.1.*', '6.2.*', '6.3.*']
php-version: ['8.1', '8.2', '8.3']
symfony-require: ['5.4.*', '6.4.*', '7.0.*']

steps:
- name: 'Setup PHP'
Expand All @@ -29,8 +28,8 @@ jobs:
- name: 'Install dependencies'
run: 'composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist'

- name: 'Execute PHP CodeSniffer'
run: 'vendor/bin/phpcs -p'
- name: 'Execute Easy Coding Standard'
run: 'vendor/bin/ecs'

phpstan:
name: 'PHPStan'
Expand All @@ -40,8 +39,8 @@ jobs:

strategy:
matrix:
php-version: ['7.4', '8.0', '8.1', '8.2']
symfony-require: ['5.4.*', '6.0.*', '6.1.*', '6.2.*', '6.3.*']
php-version: ['8.1', '8.2', '8.3']
symfony-require: ['5.4.*', '6.4.*', '7.0.*']

steps:
- name: 'Setup PHP'
Expand Down
11 changes: 5 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: 'Tests'

on:
push:
branches: ['*']
push

jobs:
unit:
Expand All @@ -13,8 +12,8 @@ jobs:

strategy:
matrix:
php-version: ['7.4', '8.0', '8.1', '8.2']
symfony-require: ['5.4.*', '6.0.*', '6.1.*', '6.2.*', '6.3.*']
php-version: ['8.1', '8.2', '8.3']
symfony-require: ['5.4.*', '6.4.*', '7.0.*']

steps:
- name: 'Setup PHP'
Expand All @@ -36,13 +35,13 @@ jobs:
name: 'Code coverage'
runs-on: 'ubuntu-latest'
env:
SYMFONY_REQUIRE: '6.3.*'
SYMFONY_REQUIRE: '7.0.*'

steps:
- name: 'Setup PHP'
uses: 'shivammathur/setup-php@v2'
with:
php-version: '8.2'
php-version: '8.3'
coverage: 'pcov'

- name: 'Checkout sources'
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/.task/
/docker/
/var/
/vendor/
/.phpcs-cache
/.phpunit.result.cache
/composer.lock
/Makefile
/Taskfile.yaml
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ Available options for the `ImageType`:
- `cancel_button_class` (`string`): CSS class of the "cancel" button (default: `''`)
- `save_button_class` (`string`): CSS class of the "save" button (default: `''`)
- `download_uri` (`string`): the path where the image is located (default: `null`, automatically set)
- `show_image` (`bool`): whether the image should be rendered in the form or not (default: `null`, will default to `true` in next major)
- ~~`download_link` (`bool`): whether the image should be rendered in the form or not (default: `true`)~~ **Deprecated, will be removed (replaced by `show_image`) in next major**
- `show_image` (`bool`): whether the image should be rendered in the form or not (default: `true`)
- `file_upload_enabled` (`bool`): whether to enable the file upload widget or not (default: `true`)
- `remote_url_enabled` (`bool`): whether to enable the remote url widget or not (default: `true`)
- `rotation_enabled` (`bool`): whether to enable the rotation or not (default: `false`)
Expand Down
15 changes: 9 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
}
],
"require": {
"php": "^7.4|^8.0",
"php": "^8.1",
"ext-fileinfo": "*",
"ext-json": "*",
"symfony/form": "^5.4|^6.0",
"vich/uploader-bundle": "^1.0|^2.0"
"symfony/form": "^5.4|^6.4|^7.0",
"vich/uploader-bundle": "^2.0"
},
"require-dev": {
"phpstan/phpstan": "^1.9",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.6",
"squizlabs/php_codesniffer": "^3.7",
"symfony/phpunit-bridge": "^6.2"
"symfony/phpunit-bridge": "^7.0",
"symplify/easy-coding-standard": "^12.0"
},
"autoload": {
"psr-4": {
Expand All @@ -34,6 +34,9 @@
}
},
"config": {
"audit": {
"abandoned": "report"
},
"sort-packages": true
},
"minimum-stability": "stable",
Expand Down
43 changes: 43 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

use PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\ForbiddenFunctionsSniff;
use PhpCsFixer\Fixer\FunctionNotation\FunctionDeclarationFixer;
use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayListItemNewlineFixer;
use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayOpenerAndCloserNewlineFixer;
use Symplify\CodingStandard\Fixer\ArrayNotation\StandaloneLineInMultilineArrayFixer;
use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return function (ECSConfig $ecsConfig): void {
$ecsConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

$ecsConfig->sets([
SetList::ARRAY,
SetList::DOCBLOCK,
SetList::NAMESPACES,
SetList::COMMENTS,
SetList::STRICT,
SetList::PSR_12,
]);

$ecsConfig->skip([
// do not force array on multiple lines : ['foo' => $foo, 'bar' => $bar]
ArrayOpenerAndCloserNewlineFixer::class,
ArrayListItemNewlineFixer::class,
StandaloneLineInMultilineArrayFixer::class,
]);

$ecsConfig->rule(LineLengthFixer::class);
$ecsConfig->ruleWithConfiguration(ForbiddenFunctionsSniff::class, [
'forbiddenFunctions' => ['dump' => null, 'dd' => null, 'var_dump' => null, 'die' => null],
]);
$ecsConfig->ruleWithConfiguration(FunctionDeclarationFixer::class, [
'closure_fn_spacing' => 'none',
]);
};
2 changes: 2 additions & 0 deletions src/Controller/UrlToBase64Controller.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Presta\ImageBundle\Controller;

use Presta\ImageBundle\Exception\UnexpectedTypeException;
Expand Down
2 changes: 2 additions & 0 deletions src/DependencyInjection/PrestaImageExtension.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Presta\ImageBundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
Expand Down
2 changes: 2 additions & 0 deletions src/Form/DataTransformer/Base64ToImageTransformer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Presta\ImageBundle\Form\DataTransformer;

use Presta\ImageBundle\Helper\Base64Helper;
Expand Down
19 changes: 5 additions & 14 deletions src/Form/Type/ImageType.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Presta\ImageBundle\Form\Type;

use Presta\ImageBundle\Form\DataTransformer\Base64ToImageTransformer;
Expand Down Expand Up @@ -140,20 +142,10 @@ static function (Options $options): string {
->setAllowedTypes('download_uri', ['string', 'null'])
->setInfo('download_uri', 'The path where the image is located.')

->setDefault('show_image', null)
->setAllowedTypes('show_image', ['bool', 'null'])
->setDefault('show_image', true)
->setAllowedTypes('show_image', ['bool'])
->setInfo('show_image', 'Whether the image should be rendered in the form or not.')

->setDefault('download_link', true)
->setAllowedTypes('download_link', ['bool'])
->setInfo('download_link', 'Whether the image should be rendered in the form or not.')
->setDeprecated(
'download_link',
'presta/image-bundle',
'2.6.0',
'The option "download_link" is deprecated, use "show_image" instead.',
)

->setDefault('file_upload_enabled', true)
->setAllowedTypes('file_upload_enabled', ['bool'])
->setInfo('file_upload_enabled', 'Whether to enable the file upload widget or not.')
Expand Down Expand Up @@ -204,8 +196,7 @@ public function buildView(FormView $view, FormInterface $form, array $options):
$view->vars['upload_mimetype'] = $options['upload_mimetype'];
$view->vars['upload_quality'] = $options['upload_quality'];

$showImage = $options['show_image'] ?? $options['download_link'];
if ($showImage && $downloadUri = $options['download_uri'] ?? $this->generateDownloadUri($form)) {
if ($options['show_image'] && $downloadUri = $options['download_uri'] ?? $this->generateDownloadUri($form)) {
$view->vars['download_uri'] = $downloadUri;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Helper/Base64Helper.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Presta\ImageBundle\Helper;

trait Base64Helper
Expand Down
2 changes: 2 additions & 0 deletions src/Model/AspectRatio.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Presta\ImageBundle\Model;

class AspectRatio
Expand Down
2 changes: 2 additions & 0 deletions src/PrestaImageBundle.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Presta\ImageBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;
Expand Down
15 changes: 8 additions & 7 deletions tests/Unit/Form/DataTransformer/Base64ToImageTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Presta\ImageBundle\Tests\Unit\Form\DataTransformer;

use Presta\ImageBundle\Form\DataTransformer\Base64ToImageTransformer;
use PHPUnit\Framework\TestCase;
use Presta\ImageBundle\Form\DataTransformer\Base64ToImageTransformer;
use Symfony\Component\HttpFoundation\File\File;

final class Base64ToImageTransformerTest extends TestCase
Expand Down Expand Up @@ -61,13 +61,14 @@ public function validOriginalValues(): iterable

public function invalidOriginalValues(): iterable
{
$fileClass = File::class;

yield 'an empty value (null) should return an empty (null) base64' => [['base64' => null], null];
yield 'a value different from '
. File::class
. ' should return an empty (null) base64' => [['base64' => null], new \stdClass()];
yield 'a '
. File::class
. ' object not related to a file on the filesystem should return an empty (null) base64' => [
yield "a value different from $fileClass should return an empty (null) base64" => [
['base64' => null],
new \stdClass(),
];
yield "a $fileClass object not related to a file on the filesystem should return an empty (null) base64" => [
['base64' => null],
new File('/tmp/foo.png', false),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ public function deletableSubmittedData(): iterable

public function notDeletableSubmittedData(): iterable
{
yield 'no "delete" checkbox data' => [
[],
];
yield 'no "delete" checkbox data' => [[]];
yield 'the "delete" checkbox not checked' => [
['delete' => false],
];
Expand Down
6 changes: 2 additions & 4 deletions tests/Unit/Form/ImageTypeTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
abstract class ImageTypeTestCase extends TypeTestCase
{
protected const ALLOW_DELETE_OPTIONS = ['allow_delete' => true, 'required' => false];
protected const ALLOW_DOWNLOAD_OPTIONS = ['download_link' => true];
protected const ALLOW_DOWNLOAD_OPTIONS = ['show_image' => true];

/**
* @var MockObject&StorageInterface
Expand Down Expand Up @@ -73,9 +73,7 @@ protected function getExtensions(): array
{
$type = new ImageType($this->storage, $this->createUploadHandler());

return [
new PreloadedExtension([$type], []),
];
return [new PreloadedExtension([$type], [])];
}

protected function createUploadHandler(): UploadHandler
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/Form/Type/ImageTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ public function testShouldNotRemoveTheFileFromTheFilesystemIfCreated(bool $allow
/**
* @dataProvider downloadableConfig
*/
public function testShouldAddDownloadUriToTheViewVars(Book $data, bool $downloadLink): void
public function testShouldAddDownloadUriToTheViewVars(Book $data, bool $showImage): void
{
\assert(null !== $data->imageName);

$expected = "/book/$data->imageName";
$options = ['download_link' => $downloadLink];
$options = ['show_image' => $showImage];

$form = $this->factory
->create(FormType::class, $data)
Expand Down Expand Up @@ -178,7 +178,7 @@ public function notDeletableOptions(): iterable

public function downloadableConfig(): iterable
{
yield 'the "download_link" option set to true when created with an object related to an existing file' => [
yield 'the "show_image" option set to true when created with an object related to an existing file' => [
Book::illustrated('foo.png'),
true,
];
Expand All @@ -187,6 +187,6 @@ public function downloadableConfig(): iterable
public function notDownloadableConfig(): iterable
{
yield 'no data (null)' => [null, self::ALLOW_DELETE_OPTIONS];
yield 'no download link' => [Book::illustrated('foo.png'), ['download_link' => false]];
yield 'no download uri' => [Book::illustrated('foo.png'), ['show_image' => false]];
}
}

0 comments on commit 53d41a7

Please sign in to comment.