Skip to content

Commit

Permalink
Remove deprecated code related to post processors
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed Nov 6, 2021
1 parent 2be422a commit 2ef3b99
Show file tree
Hide file tree
Showing 13 changed files with 7 additions and 231 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/.idea/
/.php_cs.cache
/.php-cs-fixer.cache
/.phpunit.result.cache
/bin/
/composer.lock
Expand Down
6 changes: 3 additions & 3 deletions doc/post-processors/jpeg-optim.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ To add this post-processor to the filter set created in the
thumbnail: { size: [120, 90], mode: outbound }
background: { size: [124, 94], position: center, color: '#000' }
post_processors:
jpegoptim: { strip_all: true, max: 70, progressive: true }
jpegoptim: { strip_all: true, quality: 70, progressive: true }
This configuration enables metadata stripping and progressive JPEG encoding, and sets
a maximum quality factor of 70 for the resulting image binary.
Expand All @@ -45,7 +45,7 @@ Options
**strip_all:** ``bool``
Removes all comments, EXIF markers, and other image metadata.

**max:** ``int``
**quality:** ``int``
Sets the maximum image quality factor.

**progressive:** ``bool``
Expand All @@ -58,7 +58,7 @@ Parameters
**liip_imagine.jpegoptim.stripAll:** ``bool``
Removes all comments, EXIF markers, and other metadata from the image binary.

**liip_imagine.jpegoptim.max:** ``int``
**liip_imagine.jpegoptim.quality:** ``int``
Assigns the maximum quality factor for the image binary.

**liip_imagine.jpegoptim.progressive:** ``bool``
Expand Down
4 changes: 2 additions & 2 deletions doc/post-processors/png-opti.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ To add this post-processor to the filter set created in the
thumbnail: { size: [120, 90], mode: outbound }
background: { size: [124, 94], position: center, color: '#000' }
post_processors:
optipng: { strip_all: true, level: 5 }
optipng: { strip: true, level: 5 }
This configuration enables metadata stripping, and sets a maximum optimization factor of 5
for the resulting image binary.
Expand Down Expand Up @@ -77,7 +77,7 @@ Options
Parameters
----------

**liip_imagine.optipng.stripAll:** ``bool``
**liip_imagine.optipng.strip:** ``bool``
Removes all comments, EXIF markers, and other metadata from the image binary.

**liip_imagine.optipng.level:** ``int``
Expand Down
2 changes: 1 addition & 1 deletion doc/post-processors/png-quant.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ To add this post-processor to the filter set created in the
thumbnail: { size: [120, 90], mode: outbound }
background: { size: [124, 94], position: center, color: '#000' }
post_processors:
pngquant: { quality: "75-85" }
pngquant: { quality: [75, 85] }
This configuration sets a quality factor range of 75 to 85 for the resulting image binary.

Expand Down
7 changes: 0 additions & 7 deletions src/Imagine/Filter/PostProcessor/AbstractPostProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,4 @@ protected function isSuccessfulProcess(Process $process, array $validReturns = [

return true;
}

protected function triggerSetterMethodDeprecation(string $method): void
{
@trigger_error(sprintf('The %s() method was deprecated in 2.2 and will be removed in 3.0. You must '
.'setup the class state via its __construct() method. You can still pass filter-specific options to the '.
'process() method to overwrite behavior.', $method), E_USER_DEPRECATED);
}
}
59 changes: 0 additions & 59 deletions src/Imagine/Filter/PostProcessor/JpegOptimPostProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,54 +55,6 @@ public function __construct($executablePath = '/usr/bin/jpegoptim', $strip = tru
$this->progressive = $progressive;
}

/**
* @deprecated All post-processor setters have been deprecated in 2.2 for removal in 3.0. You must only use the
* class's constructor to set the property state.
*
* @param int $maxQuality
*
* @return JpegOptimPostProcessor
*/
public function setMax($maxQuality)
{
$this->triggerSetterMethodDeprecation(__METHOD__);
$this->quality = $maxQuality;

return $this;
}

/**
* @deprecated All post-processor setters have been deprecated in 2.2 for removal in 3.0. You must only use the
* class's constructor to set the property state.
*
* @param bool $progressive
*
* @return JpegOptimPostProcessor
*/
public function setProgressive($progressive)
{
$this->triggerSetterMethodDeprecation(__METHOD__);
$this->progressive = $progressive;

return $this;
}

/**
* @deprecated All post-processor setters have been deprecated in 2.2 for removal in 3.0. You must only use the
* class's constructor to set the property state.
*
* @param bool $strip
*
* @return JpegOptimPostProcessor
*/
public function setStripAll($strip)
{
$this->triggerSetterMethodDeprecation(__METHOD__);
$this->strip = $strip;

return $this;
}

/*
* @throws ProcessFailedException
*/
Expand Down Expand Up @@ -144,17 +96,6 @@ private function getProcessArguments(array $options = []): array
$arguments[] = '--strip-all';
}

if (isset($options['max'])) {
@trigger_error('The "max" option was deprecated in 2.2 and will be removed in 3.0. '.
'Instead, use the "quality" option.', E_USER_DEPRECATED);

if (isset($options['quality'])) {
throw new InvalidOptionException('the "max" and "quality" options cannot both be set', $options);
}

$options['quality'] = $options['max'];
}

if ($quality = $options['quality'] ?? $this->quality) {
if (!\in_array($quality, range(0, 100), true)) {
throw new InvalidOptionException('the "quality" option must be an int between 0 and 100', $options);
Expand Down
16 changes: 0 additions & 16 deletions src/Imagine/Filter/PostProcessor/MozJpegPostProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,6 @@ public function __construct($executablePath = '/opt/mozjpeg/bin/cjpeg', $quality
$this->quality = $quality;
}

/**
* @deprecated All post-processor setters have been deprecated in 2.2 for removal in 3.0. You must only use the
* class's constructor to set the property state.
*
* @param int $quality
*
* @return MozJpegPostProcessor
*/
public function setQuality($quality)
{
$this->triggerSetterMethodDeprecation(__METHOD__);
$this->quality = $quality;

return $this;
}

/*
* @throws ProcessFailedException
*/
Expand Down
11 changes: 0 additions & 11 deletions src/Imagine/Filter/PostProcessor/OptiPngPostProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,6 @@ private function getProcessArguments(array $options = []): array
$arguments[] = sprintf('-o%d', $level);
}

if (isset($options['strip_all'])) {
@trigger_error('The "strip_all" option was deprecated in 2.2 and will be removed in 3.0. '.
'Instead, use the "strip" option.', E_USER_DEPRECATED);

if (isset($options['strip'])) {
throw new InvalidOptionException('the "strip" and "strip_all" options cannot both be set', $options);
}

$options['strip'] = $options['strip_all'];
}

if ($strip = $options['strip'] ?? $this->strip) {
$arguments[] = '-strip';
$arguments[] = true === $strip ? 'all' : $strip;
Expand Down
26 changes: 0 additions & 26 deletions src/Imagine/Filter/PostProcessor/PngquantPostProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,6 @@ public function __construct($executablePath = '/usr/bin/pngquant', $quality = [8
$this->quality = $quality;
}

/**
* @deprecated All post-processor setters have been deprecated in 2.2 for removal in 3.0. You must only use the
* class's constructor to set the property state.
*
* @param string $quality
*
* @return PngquantPostProcessor
*/
public function setQuality($quality)
{
$this->triggerSetterMethodDeprecation(__METHOD__);
$this->quality = $quality;

return $this;
}

/*
* @throws ProcessFailedException
*/
Expand Down Expand Up @@ -91,16 +75,6 @@ private function getProcessArguments(array $options = []): array
$arguments = [$this->executablePath];

if ($quality = $options['quality'] ?? $this->quality) {
if (\is_string($quality) && false !== mb_strpos($quality, '-')) {
@trigger_error('Passing the "quality" option as a string was deprecated in 2.2 and '.
'will be removed in 3.0. Instead, pass wither an integer representing the max value or an array '.
'representing the minimum and maximum values.', E_USER_DEPRECATED);

$quality = array_map(function ($q) {
return (int) $q;
}, explode('-', $quality));
}

if (!\is_array($quality)) {
$quality = [0, (int) $quality];
}
Expand Down
50 changes: 0 additions & 50 deletions tests/Imagine/Filter/PostProcessor/JpegOptimPostProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,6 @@
*/
class JpegOptimPostProcessorTest extends AbstractPostProcessorTestCase
{
/**
* @group legacy
* @expectedDeprecation The %s::setMax() method was deprecated in %s and will be removed in %s. You must setup the class state via its __construct() method. You can still pass filter-specific options to the process() method to overwrite behavior.
*/
public function testDeprecatedSetMaxMethod(): void
{
$this->getPostProcessorInstance()->setMax(50);
}

/**
* @group legacy
* @expectedDeprecation The %s::setProgressive() method was deprecated in %s and will be removed in %s. You must setup the class state via its __construct() method. You can still pass filter-specific options to the process() method to overwrite behavior.
*/
public function testDeprecatedSetProgressiveMethod(): void
{
$this->getPostProcessorInstance()->setProgressive(50);
}

/**
* @group legacy
* @expectedDeprecation The %s::setStripAll() method was deprecated in %s and will be removed in %s. You must setup the class state via its __construct() method. You can still pass filter-specific options to the process() method to overwrite behavior.
*/
public function testDeprecatedSetStripAllMethod(): void
{
$this->getPostProcessorInstance()->setStripAll(50);
}

public function testInvalidLevelOption(): void
{
$this->expectException(InvalidOptionException::class);
Expand All @@ -58,29 +31,6 @@ public function testInvalidLevelOption(): void
$this->getProcessArguments(['quality' => 1000]);
}

/**
* @group legacy
*
* @expectedDeprecation The "max" option was deprecated in %s and will be removed in %s. Instead, use the "quality" option.
*/
public function testOptionThrowsWhenBothMaxAndQualityAreSet(): void
{
$this->expectException(InvalidOptionException::class);
$this->expectExceptionMessage('the "max" and "quality" options cannot both be set');

$this->getProcessArguments(['max' => 50, 'quality' => 50]);
}

/**
* @group legacy
*
* @expectedDeprecation The "max" option was deprecated in %s and will be removed in %s. Instead, use the "quality" option.
*/
public function testInvalidStripDeprecationMessage(): void
{
$this->assertContains('--max=50', $this->getProcessArguments(['max' => 50]));
}

public static function provideProcessArgumentsData(): array
{
$data = [
Expand Down
10 changes: 0 additions & 10 deletions tests/Imagine/Filter/PostProcessor/MozJpegPostProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@
*/
class MozJpegPostProcessorTest extends AbstractPostProcessorTestCase
{
/**
* @group legacy
*
* @expectedDeprecation The %s::setQuality() method was deprecated in %s and will be removed in %s. You must setup the class state via its __construct() method. You can still pass filter-specific options to the process() method to overwrite behavior.
*/
public function testDeprecatedSetQualityMethod(): void
{
$this->getPostProcessorInstance()->setQuality(50);
}

public static function provideProcessArgumentsData(): array
{
$data = [
Expand Down
26 changes: 0 additions & 26 deletions tests/Imagine/Filter/PostProcessor/OptiPngPostProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,6 @@ public function testInvalidInterlaceOption(): void
$this->getProcessArguments(['interlace_type' => 10]);
}

/**
* @group legacy
*
* @expectedDeprecation The "strip_all" option was deprecated in %s and will be removed in %s. Instead, use the "strip" option.
*/
public function testInvalidStripOptionAndDeprecation(): void
{
$this->expectException(InvalidOptionException::class);
$this->expectExceptionMessage('the "strip" and "strip_all" options cannot both be set');

$this->getProcessArguments(['strip_all' => true, 'strip' => 'all']);
}

/**
* @group legacy
*
* @expectedDeprecation The "strip_all" option was deprecated in %s and will be removed in %s. Instead, use the "strip" option.
*/
public function testInvalidStripDeprecationMessage(): void
{
$arguments = $this->getProcessArguments(['strip_all' => true]);

$this->assertSame('all', array_pop($arguments));
$this->assertSame('-strip', array_pop($arguments));
}

public static function provideSetupProcessBuilderData(): array
{
$data = [
Expand Down
20 changes: 0 additions & 20 deletions tests/Imagine/Filter/PostProcessor/PngquantPostProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,6 @@
*/
class PngquantPostProcessorTest extends AbstractPostProcessorTestCase
{
/**
* @group legacy
*
* @expectedDeprecation The %s::setQuality() method was deprecated in %s and will be removed in %s. You must setup the class state via its __construct() method. You can still pass filter-specific options to the process() method to overwrite behavior.
*/
public function testDeprecatedSetQualityMethod(): void
{
$this->getPostProcessorInstance()->setQuality(50);
}

/**
* @group legacy
*
* @expectedDeprecation Passing the "quality" option as a string was deprecated in %s and will be removed in %s. Instead, pass wither an integer representing the max value or an array representing the minimum and maximum values.
*/
public function testQualityOptionDeprecation(): void
{
$this->getProcessArguments(['quality' => '0-100']);
}

public function testQualityOptionThrowsOnLargerMinThanMaxValue(): void
{
$this->expectException(InvalidOptionException::class);
Expand Down

0 comments on commit 2ef3b99

Please sign in to comment.