Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimized code #947

Merged
merged 1 commit into from May 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/Intervention/Image/AbstractColor.php
Expand Up @@ -2,6 +2,9 @@

namespace Intervention\Image;

use Intervention\Image\Exception\NotReadableException;
use Intervention\Image\Exception\NotSupportedException;

abstract class AbstractColor
{
/**
Expand Down Expand Up @@ -136,7 +139,7 @@ public function parse($value)
break;

default:
throw new \Intervention\Image\Exception\NotReadableException(
throw new NotReadableException(
"Color format ({$value}) cannot be read."
);
}
Expand Down Expand Up @@ -172,7 +175,7 @@ public function format($type)
return $this;

default:
throw new \Intervention\Image\Exception\NotSupportedException(
throw new NotSupportedException(
"Color format ({$type}) is not supported."
);
}
Expand Down Expand Up @@ -216,7 +219,7 @@ protected function rgbaFromString($value)
$result[2] = ($matches[3] >= 0 && $matches[3] <= 255) ? intval($matches[3]) : 0;
$result[3] = ($matches[4] >= 0 && $matches[4] <= 1) ? $matches[4] : 0;
} else {
throw new \Intervention\Image\Exception\NotReadableException(
throw new NotReadableException(
"Unable to read color ({$value})."
);
}
Expand Down
7 changes: 4 additions & 3 deletions src/Intervention/Image/AbstractDecoder.php
Expand Up @@ -3,6 +3,7 @@
namespace Intervention\Image;

use GuzzleHttp\Psr7\Stream;
use Intervention\Image\Exception\NotReadableException;
use Psr\Http\Message\StreamInterface;

abstract class AbstractDecoder
Expand Down Expand Up @@ -80,7 +81,7 @@ public function initFromUrl($url)
return $this->initFromBinary($data);
}

throw new \Intervention\Image\Exception\NotReadableException(
throw new NotReadableException(
"Unable to init from given url (".$url.")."
);
}
Expand Down Expand Up @@ -123,7 +124,7 @@ public function initFromStream($stream)
return $this->initFromBinary($data);
}

throw new \Intervention\Image\Exception\NotReadableException(
throw new NotReadableException(
"Unable to init from given stream"
);
}
Expand Down Expand Up @@ -342,7 +343,7 @@ public function init($data)
return $this->initFromBinary(base64_decode($this->data));

default:
throw new Exception\NotReadableException("Image source not readable");
throw new NotReadableException("Image source not readable");
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/Intervention/Image/AbstractDriver.php
Expand Up @@ -2,6 +2,8 @@

namespace Intervention\Image;

use Intervention\Image\Exception\NotSupportedException;

abstract class AbstractDriver
{
/**
Expand Down Expand Up @@ -114,7 +116,7 @@ private function getCommandClassName($name)
return $classnameGlobal;
}

throw new \Intervention\Image\Exception\NotSupportedException(
throw new NotSupportedException(
"Command ({$name}) is not available for driver ({$drivername})."
);
}
Expand Down
7 changes: 5 additions & 2 deletions src/Intervention/Image/AbstractEncoder.php
Expand Up @@ -2,6 +2,9 @@

namespace Intervention\Image;

use Intervention\Image\Exception\InvalidArgumentException;
use Intervention\Image\Exception\NotSupportedException;

abstract class AbstractEncoder
{
/**
Expand Down Expand Up @@ -167,7 +170,7 @@ public function process(Image $image, $format = null, $quality = null)
break;

default:
throw new \Intervention\Image\Exception\NotSupportedException(
throw new NotSupportedException(
"Encoding format ({$format}) is not supported."
);
}
Expand Down Expand Up @@ -229,7 +232,7 @@ protected function setQuality($quality)
$quality = $quality === 0 ? 1 : $quality;

if ($quality < 0 || $quality > 100) {
throw new \Intervention\Image\Exception\InvalidArgumentException(
throw new InvalidArgumentException(
'Quality must range from 0 to 100.'
);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Intervention/Image/Commands/AbstractCommand.php
Expand Up @@ -2,6 +2,8 @@

namespace Intervention\Image\Commands;

use Intervention\Image\Commands\Argument;

abstract class AbstractCommand
{
/**
Expand Down Expand Up @@ -44,7 +46,7 @@ public function __construct($arguments)
*/
public function argument($key)
{
return new \Intervention\Image\Commands\Argument($this, $key);
return new Argument($this, $key);
}

/**
Expand Down
12 changes: 7 additions & 5 deletions src/Intervention/Image/Commands/Argument.php
Expand Up @@ -2,6 +2,8 @@

namespace Intervention\Image\Commands;

use Intervention\Image\Exception\InvalidArgumentException;

class Argument
{
/**
Expand Down Expand Up @@ -66,7 +68,7 @@ public function value($default = null)
public function required()
{
if ( ! array_key_exists($this->key, $this->command->arguments)) {
throw new \Intervention\Image\Exception\InvalidArgumentException(
throw new InvalidArgumentException(
sprintf("Missing argument %d for %s", $this->key + 1, $this->getCommandName())
);
}
Expand Down Expand Up @@ -133,7 +135,7 @@ public function type($type)
$message = sprintf('Missing argument for %d.', $argument);
}

throw new \Intervention\Image\Exception\InvalidArgumentException(
throw new InvalidArgumentException(
$message
);
}
Expand All @@ -158,7 +160,7 @@ public function between($x, $y)
$omega = max($x, $y);

if ($value < $alpha || $value > $omega) {
throw new \Intervention\Image\Exception\InvalidArgumentException(
throw new InvalidArgumentException(
sprintf('Argument %d must be between %s and %s.', $this->key, $x, $y)
);
}
Expand All @@ -180,7 +182,7 @@ public function min($value)
}

if ($v < $value) {
throw new \Intervention\Image\Exception\InvalidArgumentException(
throw new InvalidArgumentException(
sprintf('Argument %d must be at least %s.', $this->key, $value)
);
}
Expand All @@ -202,7 +204,7 @@ public function max($value)
}

if ($v > $value) {
throw new \Intervention\Image\Exception\InvalidArgumentException(
throw new InvalidArgumentException(
sprintf('Argument %d may not be greater than %s.', $this->key, $value)
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Intervention/Image/Commands/CircleCommand.php
Expand Up @@ -4,7 +4,7 @@

use Closure;

class CircleCommand extends \Intervention\Image\Commands\AbstractCommand
class CircleCommand extends AbstractCommand
{
/**
* Draw a circle centered on given image
Expand Down
2 changes: 1 addition & 1 deletion src/Intervention/Image/Commands/EllipseCommand.php
Expand Up @@ -4,7 +4,7 @@

use Closure;

class EllipseCommand extends \Intervention\Image\Commands\AbstractCommand
class EllipseCommand extends AbstractCommand
{
/**
* Draws ellipse on given image
Expand Down
3 changes: 2 additions & 1 deletion src/Intervention/Image/Commands/ExifCommand.php
Expand Up @@ -3,6 +3,7 @@
namespace Intervention\Image\Commands;

use Intervention\Image\Exception\NotReadableException;
use Intervention\Image\Exception\NotSupportedException;

class ExifCommand extends AbstractCommand
{
Expand All @@ -18,7 +19,7 @@ class ExifCommand extends AbstractCommand
public function execute($image)
{
if (!function_exists('exif_read_data')) {
throw new \Intervention\Image\Exception\NotSupportedException(
throw new NotSupportedException(
"Reading Exif data is not supported by this PHP installation."
);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Intervention/Image/Commands/IptcCommand.php
Expand Up @@ -2,6 +2,8 @@

namespace Intervention\Image\Commands;

use Intervention\Image\Exception\NotSupportedException;

class IptcCommand extends AbstractCommand
{
/**
Expand All @@ -13,7 +15,7 @@ class IptcCommand extends AbstractCommand
public function execute($image)
{
if ( ! function_exists('iptcparse')) {
throw new \Intervention\Image\Exception\NotSupportedException(
throw new NotSupportedException(
"Reading Iptc data is not supported by this PHP installation."
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Intervention/Image/Commands/LineCommand.php
Expand Up @@ -4,7 +4,7 @@

use Closure;

class LineCommand extends \Intervention\Image\Commands\AbstractCommand
class LineCommand extends AbstractCommand
{
/**
* Draws line on given image
Expand Down
7 changes: 4 additions & 3 deletions src/Intervention/Image/Commands/PolygonCommand.php
Expand Up @@ -3,8 +3,9 @@
namespace Intervention\Image\Commands;

use Closure;
use Intervention\Image\Exception\InvalidArgumentException;

class PolygonCommand extends \Intervention\Image\Commands\AbstractCommand
class PolygonCommand extends AbstractCommand
{
/**
* Draw a polygon on given image
Expand All @@ -21,13 +22,13 @@ public function execute($image)

// check if number if coordinates is even
if ($vertices_count % 2 !== 0) {
throw new \Intervention\Image\Exception\InvalidArgumentException(
throw new InvalidArgumentException(
"The number of given polygon vertices must be even."
);
}

if ($vertices_count < 6) {
throw new \Intervention\Image\Exception\InvalidArgumentException(
throw new InvalidArgumentException(
"You must have at least 3 points in your array."
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Intervention/Image/Commands/RectangleCommand.php
Expand Up @@ -4,7 +4,7 @@

use Closure;

class RectangleCommand extends \Intervention\Image\Commands\AbstractCommand
class RectangleCommand extends AbstractCommand
{
/**
* Draws rectangle on given image
Expand Down
2 changes: 1 addition & 1 deletion src/Intervention/Image/Commands/TextCommand.php
Expand Up @@ -4,7 +4,7 @@

use Closure;

class TextCommand extends \Intervention\Image\Commands\AbstractCommand
class TextCommand extends AbstractCommand
{
/**
* Write text on given image
Expand Down
4 changes: 3 additions & 1 deletion src/Intervention/Image/Filters/DemoFilter.php
Expand Up @@ -2,6 +2,8 @@

namespace Intervention\Image\Filters;

use Intervention\Image\Image;

class DemoFilter implements FilterInterface
{
/**
Expand Down Expand Up @@ -32,7 +34,7 @@ public function __construct($size = null)
* @param \Intervention\Image\Image $image
* @return \Intervention\Image\Image
*/
public function applyFilter(\Intervention\Image\Image $image)
public function applyFilter(Image $image)
{
$image->pixelate($this->size);
$image->greyscale();
Expand Down
4 changes: 3 additions & 1 deletion src/Intervention/Image/Filters/FilterInterface.php
Expand Up @@ -2,6 +2,8 @@

namespace Intervention\Image\Filters;

use Intervention\Image\Image;

interface FilterInterface
{
/**
Expand All @@ -10,5 +12,5 @@ interface FilterInterface
* @param \Intervention\Image\Image $image
* @return \Intervention\Image\Image
*/
public function applyFilter(\Intervention\Image\Image $image);
public function applyFilter(Image $image);
}
3 changes: 2 additions & 1 deletion src/Intervention/Image/Gd/Color.php
Expand Up @@ -3,6 +3,7 @@
namespace Intervention\Image\Gd;

use Intervention\Image\AbstractColor;
use Intervention\Image\Exception\NotSupportedException;

class Color extends AbstractColor
{
Expand Down Expand Up @@ -134,7 +135,7 @@ public function initFromRgba($r, $g, $b, $a = 1)
*/
public function initFromObject($value)
{
throw new \Intervention\Image\Exception\NotSupportedException(
throw new NotSupportedException(
"GD colors cannot init from ImagickPixel objects."
);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Intervention/Image/Gd/Commands/BackupCommand.php
Expand Up @@ -2,7 +2,9 @@

namespace Intervention\Image\Gd\Commands;

class BackupCommand extends \Intervention\Image\Commands\AbstractCommand
use Intervention\Image\Commands\AbstractCommand;

class BackupCommand extends AbstractCommand
{
/**
* Saves a backups of current state of image core
Expand Down
4 changes: 3 additions & 1 deletion src/Intervention/Image/Gd/Commands/BlurCommand.php
Expand Up @@ -2,7 +2,9 @@

namespace Intervention\Image\Gd\Commands;

class BlurCommand extends \Intervention\Image\Commands\AbstractCommand
use Intervention\Image\Commands\AbstractCommand;

class BlurCommand extends AbstractCommand
{
/**
* Applies blur effect on image
Expand Down
4 changes: 3 additions & 1 deletion src/Intervention/Image/Gd/Commands/BrightnessCommand.php
Expand Up @@ -2,7 +2,9 @@

namespace Intervention\Image\Gd\Commands;

class BrightnessCommand extends \Intervention\Image\Commands\AbstractCommand
use Intervention\Image\Commands\AbstractCommand;

class BrightnessCommand extends AbstractCommand
{
/**
* Changes image brightness
Expand Down
4 changes: 3 additions & 1 deletion src/Intervention/Image/Gd/Commands/ColorizeCommand.php
Expand Up @@ -2,7 +2,9 @@

namespace Intervention\Image\Gd\Commands;

class ColorizeCommand extends \Intervention\Image\Commands\AbstractCommand
use Intervention\Image\Commands\AbstractCommand;

class ColorizeCommand extends AbstractCommand
{
/**
* Changes balance of different RGB color channels
Expand Down