Skip to content

Commit

Permalink
Upgrade to PHP 7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jaymoulin committed Jun 26, 2017
1 parent e01840c commit 469b03f
Show file tree
Hide file tree
Showing 12 changed files with 197 additions and 198 deletions.
5 changes: 0 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
language: php
php:
- '5.3'
- '5.4'
- '5.5'
- '5.6'
- '7.0'
- '7.1'
install: composer install
script: composer phpunit
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[![Latest Stable Version](https://poser.pugx.org/femtopixel/crop/v/stable)](https://packagist.org/packages/femtopixel/crop)
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%205.3-8892BF.svg?style=flat-square)](https://php.net/)
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.0-8892BF.svg?style=flat-square)](https://php.net/)
[![Build Status](https://scrutinizer-ci.com/g/femtopixel/crop/badges/build.png?b=master)](https://scrutinizer-ci.com/g/femtopixel/crop/build-status/master)
[![Dependency Status](https://www.versioneye.com/user/projects/575fe512433d18002c19d66d/badge.svg?style=flat)](https://www.versioneye.com/user/projects/575fe512433d18002c19d66d)
Expand Down
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
"name": "femtopixel/crop",
"description": "PHP Component to resize images from a configuration file",
"require": {
"php": "^5.3 || ^7.0",
"ext-gd": "*"
"php": "^7.1"
},
"require-dev": {
"phpmd/phpmd": "^2.4",
"phpunit/phpunit": "^4.0 || ^5.0",
"phpunit/phpunit": "^6.0",
"phpdocumentor/phpdocumentor": "^2.9",
"squizlabs/php_codesniffer": "^2.6",
"sebastian/phpcpd": "^2.0",
"phploc/phploc": "^2.0 || ^3.0",
"codeclimate/php-test-reporter": "dev-master"
"phploc/phploc": "^3.0",
"codeclimate/php-test-reporter": "^0.4"
},
"autoload": {
"psr-4": {
Expand Down
52 changes: 26 additions & 26 deletions src/Crop.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types = 1);

namespace FemtoPixel\Crop;

Expand All @@ -13,39 +14,39 @@ class Crop
private $format = self::FORMAT_ORIGINAL;
private $filePath = self::FORMAT_ORIGINAL;
private $availableFormats = array();
private $defaultImage = null;
private $defaultImage = '';
private $resizeEngine = null;

/**
* @param string $filePath
* @param string $format
* @param string $defaultImage
*/
public function __construct($filePath, $format = self::FORMAT_ORIGINAL, $defaultImage = null)
public function __construct(string $filePath, string $format = self::FORMAT_ORIGINAL, string $defaultImage = '')
{
$this->setFilePath($filePath)->setFormat($format)->setDefaultImage($defaultImage);
}

/**
* Define all formats from an array
* @param array $formats
* @return $this
* @return Crop
*/
public function setFormatsFromArray(array $formats)
public function setFormatsFromArray(array $formats) : Crop
{
$this->availableFormats = (array)$formats;
$this->availableFormats = $formats;
return $this;
}

/**
* Define a format type to a name
* @param string $formatName
* @param \FemtoPixel\Crop\Format $format
* @return $this
* @return Crop
*/
public function setAvailableFormat($formatName, \FemtoPixel\Crop\Format $format)
public function setAvailableFormat(string $formatName, \FemtoPixel\Crop\Format $format) : Crop
{
$this->availableFormats[(string)$formatName] = $format;
$this->availableFormats[$formatName] = $format;
return $this;
}

Expand Down Expand Up @@ -74,7 +75,7 @@ public function render()
* @return bool
* @codeCoverageIgnore
*/
protected function phpFileExists($filePath)
protected function phpFileExists(string $filePath) : bool
{
return file_exists($filePath);
}
Expand All @@ -86,7 +87,7 @@ protected function phpFileExists($filePath)
* @return int
* @codeCoverageIgnore
*/
protected function phpReadfile($filename, $useIncludePath = null, $context = null)
protected function phpReadfile(string $filename, ?bool $useIncludePath = null, $context = null) : int
{
return readfile($filename, $useIncludePath, $context);
}
Expand All @@ -97,25 +98,24 @@ protected function phpReadfile($filename, $useIncludePath = null, $context = nul
* @param int $httpResponseCode
* @codeCoverageIgnore
*/
protected function phpHeader($string, $replace = null, $httpResponseCode = null)
protected function phpHeader(string $string, bool $replace = true, ?int $httpResponseCode = null)
{
$replace = !is_null($replace) ? (bool)$replace : true;
return header($string, $replace, $httpResponseCode);
}

/**
* @return string
*/
public function getFilePath()
public function getFilePath() : string
{
return $this->filePath;
}

/**
* @param string $filePath
* @return $this
* @return Crop
*/
public function setFilePath($filePath)
public function setFilePath(string $filePath) : Crop
{
$this->filePath = (string)$filePath;
return $this;
Expand All @@ -141,17 +141,17 @@ protected function getComputedDefaultFilePath()
* Returns format name defined
* @return string
*/
public function getFormat()
public function getFormat() : string
{
return $this->format;
}

/**
* Define format name to get
* @param string $format
* @return $this
* @return Crop
*/
public function setFormat($format = self::FORMAT_ORIGINAL)
public function setFormat(string $format = self::FORMAT_ORIGINAL) : Crop
{
$this->format = (string)$format;
return $this;
Expand All @@ -162,7 +162,7 @@ public function setFormat($format = self::FORMAT_ORIGINAL)
* @return \FemtoPixel\Crop\Format[]|\FemtoPixel\Crop\Format
* @throws Exception\FormatNotAvailable
*/
public function getAvailableFormat($format = null)
public function getAvailableFormat(?string $format = null)
{
if ($format === null) {
return $this->availableFormats;
Expand All @@ -178,24 +178,24 @@ public function getAvailableFormat($format = null)
* @param string $format
* @return bool
*/
public function isAvailableFormat($format)
public function isAvailableFormat(string $format) : bool
{
return isset($this->availableFormats[$format]);
}

/**
* @return string
*/
public function getDefaultImage()
public function getDefaultImage() : string
{
return $this->defaultImage;
}

/**
* @param string $defaultFilePath
* @return $this
* @return Crop
*/
public function setDefaultImage($defaultFilePath = null)
public function setDefaultImage(?string $defaultFilePath = null) : Crop
{
$this->defaultImage = $defaultFilePath
? (string)$defaultFilePath
Expand All @@ -207,7 +207,7 @@ public function setDefaultImage($defaultFilePath = null)
* @return ResizeEngine
* @codeCoverageIgnore
*/
protected function getResizeEngine()
protected function getResizeEngine() : ResizeEngine
{
return ($this->resizeEngine = ($this->resizeEngine ?: new ResizeEngine()));
}
Expand All @@ -226,10 +226,10 @@ protected function resize($filePath, array $info)
$formatFull = isset($formatDestination[Format::FULL]) ? $formatDestination[Format::FULL] : Format::FULL_NONE;
if ($formatFull == Format::FULL_WIDTH) {
$width = (int)$formatDestination[Format::WIDTH];
$height = (int)$formatDestination[Format::WIDTH] * (1 / $ratioOriginal);
$height = (int) ($formatDestination[Format::WIDTH] * (1 / $ratioOriginal));
} elseif ($formatFull == Format::FULL_HEIGHT) {
$height = (int)$formatDestination[Format::HEIGHT];
$width = (int)$formatDestination[Format::HEIGHT] * $ratioOriginal;
$width = (int) ($formatDestination[Format::HEIGHT] * $ratioOriginal);
}
$this->getResizeEngine()
->resize(
Expand Down
1 change: 1 addition & 0 deletions src/Exception.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types = 1);

namespace FemtoPixel\Crop;

Expand Down
1 change: 1 addition & 0 deletions src/Exception/FormatFullModeNotAvailable.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types = 1);

namespace FemtoPixel\Crop\Exception;

Expand Down
1 change: 1 addition & 0 deletions src/Exception/FormatNotAvailable.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types = 1);

namespace FemtoPixel\Crop\Exception;

Expand Down
43 changes: 22 additions & 21 deletions src/Format.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types = 1);

namespace FemtoPixel\Crop;

Expand Down Expand Up @@ -29,10 +30,10 @@ class Format implements \ArrayAccess
* @param int $width
* @param int $height
* @param string $full
* @param null $defaultImage
* @param string|null $defaultImage
* @throws FormatFullModeNotAvailable
*/
public function __construct($width, $height, $full = self::FULL_NONE, $defaultImage = null)
public function __construct(int $width, int $height, string $full = self::FULL_NONE, ?string $defaultImage = null)
{
$this->setFullMode($full)
->setHeight($height)
Expand All @@ -44,30 +45,30 @@ public function __construct($width, $height, $full = self::FULL_NONE, $defaultIm

/**
* @param int $width
* @return $this
* @return Format
*/
public function setWidth($width)
public function setWidth(int $width) : Format
{
$this->data[self::WIDTH] = (int)$width;
$this->data[self::WIDTH] = $width;
return $this;
}

/**
* @param int $height
* @return $this
* @return Format
*/
public function setHeight($height)
public function setHeight(int $height) : Format
{
$this->data[self::HEIGHT] = (int)$height;
$this->data[self::HEIGHT] = $height;
return $this;
}

/**
* @param string $fullMode
* @return $this
* @return Format
* @throws FormatFullModeNotAvailable
*/
public function setFullMode($fullMode = self::FULL_NONE)
public function setFullMode(string $fullMode = self::FULL_NONE) : Format
{
$allowed = array(
self::FULL_NONE => self::FULL_NONE,
Expand All @@ -85,32 +86,32 @@ public function setFullMode($fullMode = self::FULL_NONE)
/**
* @return int
*/
public function getWidth()
public function getWidth() : int
{
return $this->data[self::WIDTH];
}

/**
* @return int
*/
public function getHeight()
public function getHeight() : int
{
return $this->data[self::HEIGHT];
}

/**
* @return string
*/
public function getFullMode()
public function getFullMode() : string
{
return $this->data[self::FULL];
}

/**
* @param string|null $defaultImage
* @return $this
* @return Format
*/
public function setDefaultImage($defaultImage = null)
public function setDefaultImage(?string $defaultImage = null) : Format
{
$this->data[self::DEFAULT_IMAGE] = (string)$defaultImage;
return $this;
Expand All @@ -119,22 +120,22 @@ public function setDefaultImage($defaultImage = null)
/**
* @return string|null
*/
public function getDefaultImage()
public function getDefaultImage() : ?string
{
return $this->data[self::DEFAULT_IMAGE];
}

/**
* @param string $offset
* @param string|int $offset
* @return bool
*/
public function offsetExists($offset)
public function offsetExists($offset) : bool
{
return isset($this->data[$offset]);
}

/**
* @param string $offset
* @param string|int $offset
* @return mixed
*/
public function offsetGet($offset)
Expand All @@ -143,7 +144,7 @@ public function offsetGet($offset)
}

/**
* @param string $offset
* @param string|int $offset
* @param mixed $value
*/
public function offsetSet($offset, $value)
Expand All @@ -152,7 +153,7 @@ public function offsetSet($offset, $value)
}

/**
* @param string $offset
* @param string|int $offset
*/
public function offsetUnset($offset)
{
Expand Down
Loading

0 comments on commit 469b03f

Please sign in to comment.