Skip to content

Commit

Permalink
Global CS fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierstoval committed Jan 13, 2021
1 parent 8391456 commit 98107af
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 138 deletions.
2 changes: 1 addition & 1 deletion Resources/references.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
'YDbDr',
'YIQ',
'YPbPr',
'YUV'
'YUV',
],
'colors' => [
'snow',
Expand Down
5 changes: 1 addition & 4 deletions Tests/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ public function __construct($name = null, array $data = [], $dataName = '')
{
parent::__construct($name, $data, $dataName);
if (!\defined('IMAGEMAGICK_DIR') || !\defined('TEST_RESOURCES_DIR')) {
throw new \RuntimeException(
"The \"IMAGEMAGICK_DIR\" constant is not defined.\n".
'The bootstrap must be correctly included before executing test suite.'
);
throw new \RuntimeException("The \"IMAGEMAGICK_DIR\" constant is not defined.\n".'The bootstrap must be correctly included before executing test suite.');
}
$this->resourcesDir = TEST_RESOURCES_DIR;
}
Expand Down
6 changes: 3 additions & 3 deletions Tests/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public function provideWrongConvertDirs(): ?\Generator
*/
public function testConvert($fileSources, string $fileOutput): void
{

$command = new Command(IMAGEMAGICK_DIR);

$response = $command
->convert($fileSources)
->output($fileOutput)
->run();
->run()
;

static::assertFileExists($fileOutput);

Expand Down Expand Up @@ -212,7 +212,7 @@ public function testColorspaceImage(): void
$this->testConvertIdentifyImage($imageOutput, 'JPEG', '180x170+0+0', '8-bit');
}

public function testMonochrome(): void
public function testMonochrome(): void
{
$command = new Command(IMAGEMAGICK_DIR);

Expand Down
59 changes: 34 additions & 25 deletions Tests/GravityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

declare(strict_types=1);

/*
* This file is part of the OrbitaleImageMagickPHP package.
*
* (c) Alexandre Rock Ancelet <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Orbitale\Component\ImageMagick\Tests;

use Orbitale\Component\ImageMagick\Command;
Expand Down Expand Up @@ -51,15 +60,15 @@ public function testGravity($gravity): void

public function provideValidGravities(): ?\Generator
{
yield 0 => ["NorthWest"];
yield 1 => ["North"];
yield 2 => ["NorthEast"];
yield 3 => ["West"];
yield 4 => ["Center"];
yield 5 => ["East"];
yield 6 => ["SouthWest"];
yield 7 => ["South"];
yield 8 => ["SouthEast"];
yield 0 => ['NorthWest'];
yield 1 => ['North'];
yield 2 => ['NorthEast'];
yield 3 => ['West'];
yield 4 => ['Center'];
yield 5 => ['East'];
yield 6 => ['SouthWest'];
yield 7 => ['South'];
yield 8 => ['SouthEast'];
}

/**
Expand All @@ -70,27 +79,27 @@ public function provideValidGravities(): ?\Generator
public function testWrongGravities($gravity): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage("Invalid gravity option, \"" .$gravity. "\" given.\nAvailable: NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast" );
$this->expectExceptionMessage('Invalid gravity option, "'.$gravity."\" given.\nAvailable: NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast");

$testGravity = new Gravity($gravity);
$testGravity->validate();
}

public function provideWrongGravities(): ?\Generator
{
yield 0 => ["Northwest"];
yield 1 => ["northwest"];
yield 2 => ["north"];
yield 3 => ["northEast"];
yield 4 => ["Northeast"];
yield 5 => ["west"];
yield 6 => ["center"];
yield 7 => ["east"];
yield 8 => ["southwest"];
yield 9 => ["south"];
yield 10 => ["southeast"];
yield 11 => ["Middle"];
yield 12 => [""];
yield 13 => [" "];
yield 0 => ['Northwest'];
yield 1 => ['northwest'];
yield 2 => ['north'];
yield 3 => ['northEast'];
yield 4 => ['Northeast'];
yield 5 => ['west'];
yield 6 => ['center'];
yield 7 => ['east'];
yield 8 => ['southwest'];
yield 9 => ['south'];
yield 10 => ['southeast'];
yield 11 => ['Middle'];
yield 12 => [''];
yield 13 => [' '];
}
}
34 changes: 8 additions & 26 deletions src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,7 @@ public function __construct(?string $magickBinaryPath = '')
}

if (0 !== $code || !$process->isSuccessful()) {
throw new \InvalidArgumentException(\sprintf(
"ImageMagick does not seem to work well, the test command resulted in an error.\n".
"Execution returned message: \"{$process->getExitCodeText()}\"\n".
"To solve this issue, please run this command and check your error messages to see if ImageMagick was correctly installed:\n%s",
$magickBinaryPath.' -version'
));
throw new \InvalidArgumentException(\sprintf("ImageMagick does not seem to work well, the test command resulted in an error.\n"."Execution returned message: \"{$process->getExitCodeText()}\"\n"."To solve this issue, please run this command and check your error messages to see if ImageMagick was correctly installed:\n%s", $magickBinaryPath.' -version'));
}

$this->ref = new References();
Expand Down Expand Up @@ -123,10 +118,7 @@ public static function findMagickBinaryPath(?string $magickBinaryPath): string
}

if (!\is_executable($magickBinaryPath)) {
throw new \InvalidArgumentException(\sprintf(
'The specified script (%s) is not executable.',
$magickBinaryPath
));
throw new \InvalidArgumentException(\sprintf('The specified script (%s) is not executable.', $magickBinaryPath));
}

return $magickBinaryPath;
Expand All @@ -151,12 +143,7 @@ private static function cleanPath(string $path, bool $rtrim = false): string
public function getExecutable(?string $binary = null): array
{
if (!\in_array($binary, static::ALLOWED_EXECUTABLES, true)) {
throw new \InvalidArgumentException(\sprintf(
"The ImageMagick executable \"%s\" is not allowed.\n".
"The only binaries allowed to be executed are the following:\n%s",
$binary,
\implode(', ', static::ALLOWED_EXECUTABLES)
));
throw new \InvalidArgumentException(\sprintf("The ImageMagick executable \"%s\" is not allowed.\n"."The only binaries allowed to be executed are the following:\n%s", $binary, \implode(', ', static::ALLOWED_EXECUTABLES)));
}

return [$this->magickBinaryPath, $binary];
Expand All @@ -179,7 +166,7 @@ public function newCommand(?string $binary = null): self
*/
public function convert($sourceFiles, bool $checkIfFileExists = true): self
{
if (!is_array($sourceFiles)) {
if (!\is_array($sourceFiles)) {
$sourceFiles = [$sourceFiles];
}

Expand Down Expand Up @@ -497,7 +484,6 @@ public function strip(): self
return $this;
}


/**
* @see http://imagemagick.org/script/command-line-options.php#monochrome
*/
Expand Down Expand Up @@ -600,7 +586,7 @@ public function autoOrient(): self
*/
public function depth(int $depth): self
{
$this->command[] = '-depth ' . $depth;
$this->command[] = '-depth '.$depth;

return $this;
}
Expand Down Expand Up @@ -665,14 +651,14 @@ public function threshold(string $threshold): self
*/
public function rawCommand(string $command, bool $append = false): self
{
$msg = <<<MSG
$msg = <<<'MSG'
This command is not safe and therefore should not be used, unless you need to use an option that is not supported yet.
Use at your own risk!
If you are certain of what you are doing, you can silence this error using the "@" sign on the instruction that executes this method.
If the option you need is not supported, please open an issue or a pull-request at https://github.com/Orbitale/ImageMagickPHP in order for us to implement the option you need! 😃
MSG
;
@trigger_error($msg, E_STRICT);
@\trigger_error($msg, E_STRICT);

if ($append) {
$this->commandToAppend[] = $command;
Expand Down Expand Up @@ -784,11 +770,7 @@ public function polyline(array $coordinates, string $strokeColor = ''): self
protected function checkExistingFile(string $file): string
{
if (!\file_exists($file)) {
throw new \InvalidArgumentException(\sprintf(
'The file "%s" is not found.'."\n".
'If the file really exists in your filesystem, then maybe it is not readable.',
$file
));
throw new \InvalidArgumentException(\sprintf('The file "%s" is not found.'."\n".'If the file really exists in your filesystem, then maybe it is not readable.', $file));
}

return self::cleanPath($file);
Expand Down
13 changes: 2 additions & 11 deletions src/ReferenceClasses/Geometry.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ public static function createFromParameters(
}

if ($aspectRatio && !\in_array($aspectRatio, self::$validRatios, true)) {
throw new \InvalidArgumentException(\sprintf(
"Invalid aspect ratio value to generate geometry, \"%s\" given.\nAvailable: %s",
$aspectRatio, \implode(', ', self::$validRatios)
));
throw new \InvalidArgumentException(\sprintf("Invalid aspect ratio value to generate geometry, \"%s\" given.\nAvailable: %s", $aspectRatio, \implode(', ', self::$validRatios)));
}
$geometry .= $aspectRatio;

Expand Down Expand Up @@ -139,13 +136,7 @@ public function validate(): string
}

if (\count($errors)) {
throw new \InvalidArgumentException(\sprintf(
"The specified geometry (%s) is invalid.\n%s\n".
"Please refer to ImageMagick command line documentation about geometry:\n%s\n",
$this->value,
\implode("\n", $errors),
'http://www.imagemagick.org/script/command-line-processing.php#geometry'
));
throw new \InvalidArgumentException(\sprintf("The specified geometry (%s) is invalid.\n%s\n"."Please refer to ImageMagick command line documentation about geometry:\n%s\n", $this->value, \implode("\n", $errors), 'http://www.imagemagick.org/script/command-line-processing.php#geometry'));
}

$this->value = \trim($this->value);
Expand Down
34 changes: 20 additions & 14 deletions src/ReferenceClasses/Gravity.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

declare(strict_types=1);

/*
* This file is part of the OrbitaleImageMagickPHP package.
*
* (c) Alexandre Rock Ancelet <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Orbitale\Component\ImageMagick\ReferenceClasses;

/**
Expand All @@ -12,15 +21,15 @@
class Gravity
{
private static $validGravity = [
"NorthWest",
"North",
"NorthEast",
"West",
"Center",
"East",
"SouthWest",
"South",
"SouthEast"
'NorthWest',
'North',
'NorthEast',
'West',
'Center',
'East',
'SouthWest',
'South',
'SouthEast',
];

/**
Expand All @@ -45,11 +54,8 @@ public function __toString(): string

public function validate(): string
{
if (!in_array($this->value, self::$validGravity, true)) {
throw new \InvalidArgumentException(\sprintf(
"Invalid gravity option, \"%s\" given.\nAvailable: %s",
$this->value, \implode(', ', self::$validGravity)
));
if (!\in_array($this->value, self::$validGravity, true)) {
throw new \InvalidArgumentException(\sprintf("Invalid gravity option, \"%s\" given.\nAvailable: %s", $this->value, \implode(', ', self::$validGravity)));
}

return $this->value;
Expand Down
Loading

0 comments on commit 98107af

Please sign in to comment.