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

Flysystem v2 #291

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at http://editorconfig.org

root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.yml]
indent_size = 2
69 changes: 69 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: ci

on: [push, pull_request]

jobs:
testsuite:
runs-on: ubuntu-18.04
strategy:
fail-fast: false
matrix:
php-version: ['7.2', '7.4', '8.0']
composer-opts: ['']
include:
- php-version: '7.2'
composer-opts: '--prefer-lowest'

steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: pcov

- name: Composer install
run: composer update ${{ matrix.composer-opts }}

- name: Run PHPUnit
run: |
if [[ ${{ matrix.php-version }} == '7.4' ]]; then
vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover
else
vendor/bin/phpunit
fi

- name: Code Coverage Report
if: matrix.php-version == '7.4'
run: |
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover coverage.clover

cs-stan:
name: Coding Standard & Static Analysis
runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
coverage: none
tools: psalm:~4.1.0

- name: Composer Install
run: composer install

- name: Run phpcs
run: vendor/bin/phpcs -p --standard=PSR12 ./src ./tests

- name: Run psalm
if: success() || failure()
run: psalm
27 changes: 23 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ php:
- 7.4
- 8.0snapshot

env:
global:
- DEFAULT=1

matrix:
fast_finish: true

include:
- php: 7.4
env: PHPCS=1 DEFAULT=0
- php: 7.2
env: STATIC_ANALYSIS=1 DEFAULT=0

cache:
directories:
- $HOME/.composer/cache
Expand All @@ -18,10 +31,16 @@ before_install:

install:
- travis_retry composer update --no-interaction --prefer-source
- if [[ $STATIC_ANALYSIS == 1 ]]; then composer require --dev psalm/phar:^3.13; fi

script:
- vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover
- if [[ $DEFAULT == 1 ]]; then vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover; fi
- if [[ $PHPCS == 1 ]]; then vendor/bin/phpcs -p --standard=PSR12 ./src ./tests; fi
- if [[ $STATIC_ANALYSIS == 1 ]]; then vendor/bin/psalm.phar; fi

after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
after_success:
- |
if [[ $DEFAULT == 1 ]]; then
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover coverage.clover
fi
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
],
"require": {
"intervention/image": "^2.4",
"league/flysystem": "^1.0",
"league/flysystem": "^2.0",
"php": "^7.2|^8.0",
"psr/http-message": "^1.0"
},
"require-dev": {
"mockery/mockery": "^1.3.3",
"phpunit/phpunit": "^8.5|^9.0",
"phpunit/php-token-stream": "^3.1|^4.0"
"phpunit/php-token-stream": "^3.1|^4.0",
"squizlabs/php_codesniffer": "^3.5"
},
"autoload": {
"psr-4": {
Expand Down
15 changes: 15 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
8 changes: 5 additions & 3 deletions src/Api/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function __construct(ImageManager $imageManager, array $manipulators)
/**
* Set the image manager.
* @param ImageManager $imageManager Intervention image manager.
* @return void
*/
public function setImageManager(ImageManager $imageManager)
{
Expand All @@ -44,14 +45,15 @@ public function setImageManager(ImageManager $imageManager)
* Get the image manager.
* @return ImageManager Intervention image manager.
*/
public function getImageManager()
public function getImageManager(): ImageManager
{
return $this->imageManager;
}

/**
* Set the manipulators.
* @param array $manipulators Collection of manipulators.
* @return void
*/
public function setManipulators(array $manipulators)
{
Expand All @@ -68,7 +70,7 @@ public function setManipulators(array $manipulators)
* Get the manipulators.
* @return array Collection of manipulators.
*/
public function getManipulators()
public function getManipulators(): array
{
return $this->manipulators;
}
Expand All @@ -79,7 +81,7 @@ public function getManipulators()
* @param array $params The manipulation params.
* @return string Manipulated image binary data.
*/
public function run($source, array $params)
public function run(string $source, array $params): string
{
$image = $this->imageManager->make($source);

Expand Down
2 changes: 1 addition & 1 deletion src/Api/ApiInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ interface ApiInterface
* @param array $params The manipulation params.
* @return string Manipulated image binary data.
*/
public function run($source, array $params);
public function run(string $source, array $params): string;
}
2 changes: 1 addition & 1 deletion src/Manipulators/Background.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Background extends BaseManipulator
* @param Image $image The source image.
* @return Image The manipulated image.
*/
public function run(Image $image)
public function run(Image $image): Image
{
if (is_null($this->bg)) {
return $image;
Expand Down
3 changes: 2 additions & 1 deletion src/Manipulators/BaseManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ abstract class BaseManipulator implements ManipulatorInterface
/**
* Set the manipulation params.
* @param array $params The manipulation params.
* @return $this
*/
public function setParams(array $params)
{
Expand All @@ -39,5 +40,5 @@ public function __get($name)
* Perform the image manipulation.
* @return Image The manipulated image.
*/
abstract public function run(Image $image);
abstract public function run(Image $image): Image;
}
10 changes: 5 additions & 5 deletions src/Manipulators/Blur.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Blur extends BaseManipulator
* @param Image $image The source image.
* @return Image The manipulated image.
*/
public function run(Image $image)
public function run(Image $image): Image
{
$blur = $this->getBlur();

Expand All @@ -27,16 +27,16 @@ public function run(Image $image)

/**
* Resolve blur amount.
* @return string The resolved blur amount.
* @return int|null The resolved blur amount.
*/
public function getBlur()
public function getBlur(): ?int
{
if (!is_numeric($this->blur)) {
return;
return null;
}

if ($this->blur < 0 or $this->blur > 100) {
return;
return null;
}

return (int) $this->blur;
Expand Down
50 changes: 26 additions & 24 deletions src/Manipulators/Border.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Border extends BaseManipulator
* @param Image $image The source image.
* @return Image The manipulated image.
*/
public function run(Image $image)
public function run(Image $image): Image
{
if ($border = $this->getBorder($image)) {
list($width, $color, $method) = $border;
Expand All @@ -41,12 +41,12 @@ public function run(Image $image)
/**
* Resolve border amount.
* @param Image $image The source image.
* @return string The resolved border amount.
* @return array|null The resolved border amount.
*/
public function getBorder(Image $image)
public function getBorder(Image $image): ?array
{
if (!$this->border) {
return;
return null;
}

$values = explode(',', $this->border);
Expand All @@ -58,6 +58,8 @@ public function getBorder(Image $image)
if ($width) {
return [$width, $color, $method];
}

return null;
}

/**
Expand All @@ -67,27 +69,27 @@ public function getBorder(Image $image)
* @param string $width The border width.
* @return double The resolved border width.
*/
public function getWidth(Image $image, $dpr, $width)
public function getWidth(Image $image, float $dpr, string $width): float
{
return (new Dimension($image, $dpr))->get($width);
return (float) (new Dimension($image, $dpr))->get($width);
}

/**
* Get formatted color.
* @param string $color The color.
* @return string The formatted color.
*/
public function getColor($color)
public function getColor(string $color): string
{
return (new Color($color))->formatted();
}

/**
* Resolve the border method.
* @param string $method The raw border method.
* @return string The resolved border method.
* @param string|null $method The raw border method.
* @return string|null The resolved border method.
*/
public function getMethod($method)
public function getMethod(?string $method): ?string
{
if (!in_array($method, ['expand', 'shrink', 'overlay'], true)) {
return 'overlay';
Expand All @@ -100,7 +102,7 @@ public function getMethod($method)
* Resolve the device pixel ratio.
* @return double The device pixel ratio.
*/
public function getDpr()
public function getDpr(): float
{
if (!is_numeric($this->dpr)) {
return 1.0;
Expand All @@ -120,13 +122,13 @@ public function getDpr()
* @param string $color The border color.
* @return Image The manipulated image.
*/
public function runOverlay(Image $image, $width, $color)
public function runOverlay(Image $image, float $width, string $color): Image
{
return $image->rectangle(
$width / 2,
$width / 2,
$image->width() - ($width / 2),
$image->height() - ($width / 2),
(int) round($width / 2),
(int) round($width / 2),
(int) round($image->width() - ($width / 2)),
(int) round($image->height() - ($width / 2)),
function ($draw) use ($width, $color) {
$draw->border($width, $color);
}
Expand All @@ -140,16 +142,16 @@ function ($draw) use ($width, $color) {
* @param string $color The border color.
* @return Image The manipulated image.
*/
public function runShrink(Image $image, $width, $color)
public function runShrink(Image $image, float $width, string $color): Image
{
return $image
->resize(
$image->width() - ($width * 2),
$image->height() - ($width * 2)
(int) round($image->width() - ($width * 2)),
(int) round($image->height() - ($width * 2))
)
->resizeCanvas(
$width * 2,
$width * 2,
(int) round($width * 2),
(int) round($width * 2),
'center',
true,
$color
Expand All @@ -163,11 +165,11 @@ public function runShrink(Image $image, $width, $color)
* @param string $color The border color.
* @return Image The manipulated image.
*/
public function runExpand(Image $image, $width, $color)
public function runExpand(Image $image, float $width, string $color): Image
{
return $image->resizeCanvas(
$width * 2,
$width * 2,
(int) round($width * 2),
(int) round($width * 2),
'center',
true,
$color
Expand Down
Loading