Skip to content

Commit 4b89e97

Browse files
authored
Merge pull request #12 from timonf/transcoder-upgrade
Support for Symfony >= 4, PHP 7.4 / 8
2 parents 4f9fe8b + 332d6ad commit 4b89e97

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+256
-180
lines changed

.github/workflows/test.yml

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: "Test"
2+
3+
on:
4+
push:
5+
pull_request:
6+
schedule:
7+
- cron: '0 03 * * 1' # At 03:00 on Monday.
8+
9+
jobs:
10+
tests:
11+
name: "Tests"
12+
13+
runs-on: ${{ matrix.operating-system }}
14+
15+
strategy:
16+
matrix:
17+
dependencies: ["lowest", "highest"]
18+
php-version:
19+
- "7.4"
20+
- "8.0"
21+
- "8.1"
22+
operating-system: ["ubuntu-latest"]
23+
24+
steps:
25+
- name: "Checkout"
26+
uses: "actions/checkout@v2"
27+
28+
- name: "Install PHP"
29+
uses: "shivammathur/setup-php@v2"
30+
with:
31+
coverage: "none"
32+
php-version: "${{ matrix.php-version }}"
33+
34+
- name: "Cache dependencies"
35+
uses: "actions/cache@v2"
36+
with:
37+
path: "~/.composer/cache"
38+
key: "php-${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }}"
39+
restore-keys: "php-${{ matrix.php-version }}-composer-"
40+
41+
- name: "Install lowest dependencies"
42+
if: ${{ matrix.dependencies == 'lowest' }}
43+
run: "composer update --prefer-lowest --prefer-dist --no-interaction --no-progress --no-suggest"
44+
45+
- name: "Install highest dependencies"
46+
if: ${{ matrix.dependencies == 'highest' }}
47+
run: "composer update --prefer-dist --no-interaction --no-progress --no-suggest"
48+
49+
- name: "Unit tests"
50+
run: "vendor/bin/phpunit"
51+
52+
- name: "Coding style"
53+
run: "vendor/bin/phpcs --report=summary"
54+
55+
- name: "Static analysis"
56+
run: "vendor/bin/phpstan --no-progress"

.scrutinizer.yml

-6
This file was deleted.

.travis.yml

-21
This file was deleted.

README.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
Transcoder Library
22
==================
33

4-
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/101113a8-06da-4547-aae8-cc9c77027c5b/mini.png)](https://insight.sensiolabs.com/projects/101113a8-06da-4547-aae8-cc9c77027c5b)
5-
[![Build Status](https://travis-ci.org/brainbits/transcoder.png?branch=master)](https://travis-ci.org/brainbits/transcoder)
6-
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/brainbits/transcoder/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/brainbits/transcoder/?branch=master)
7-
[![Scrutinizer Code Coverage](https://scrutinizer-ci.com/g/brainbits/transcoder/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/brainbits/transcoder/?branch=master)
84
[![Latest Stable Version](https://poser.pugx.org/brainbits/transcoder/v/stable.svg)](https://packagist.org/packages/brainbits/transcoder)
95
[![Total Downloads](https://poser.pugx.org/brainbits/transcoder/downloads.svg)](https://packagist.org/packages/brainbits/transcoder)
10-
[![Dependency Status](https://www.versioneye.com/php/brainbits:transcoder/master/badge.svg)](https://www.versioneye.com/php/brainbits:transcoder/master)
6+
[![Tests](https://github.com/brainbits/transcoder/actions/workflows/test.yml/badge.svg)](https://github.com/brainbits/transcoder/actions)
117

128
The Transcoder Library provides methods to transcode data.

composer.json

+9-4
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@
1919
}
2020
],
2121
"require": {
22-
"php": "^7.1",
22+
"php": "^7.4|^8.0",
2323
"psr/log": "^1.0",
24-
"symfony/process": "^2.8|^3.0"
24+
"symfony/process": ">=4.4"
2525
},
2626
"require-dev": {
27-
"phpunit/phpunit": "^6.0"
27+
"phpunit/phpunit": "^9.5",
28+
"phpspec/prophecy-phpunit": "^2.0",
29+
"squizlabs/php_codesniffer": "^3.6",
30+
"brainbits/phpcs-standard": "^5.0",
31+
"phpstan/phpstan": "^0.12.99",
32+
"brainbits/phpstan-rules": "^2.0"
2833
},
2934
"autoload": {
3035
"psr-4": { "Brainbits\\Transcoder\\": "src/" }
@@ -34,7 +39,7 @@
3439
},
3540
"extra": {
3641
"branch-alias": {
37-
"dev-master": "3.0-dev"
42+
"dev-master": "4.0-dev"
3843
}
3944
}
4045
}

phpcs.xml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHP_CodeSniffer" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
3+
<file extension="php">src/</file>
4+
<arg name="basepath" value="." />
5+
<arg name="colors" />
6+
<rule ref="Brainbits">
7+
<exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming.SuperfluousSuffix" />
8+
<exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming.SuperfluousSuffix" />
9+
</rule>
10+
</ruleset>

phpstan.neon

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
parameters:
2+
checkMissingIterableValueType: false
3+
level: max
4+
paths:
5+
- src
6+
bootstrapFiles:
7+
- vendor/autoload.php
8+
includes:
9+
- vendor/brainbits/phpstan-rules/rules.neon

phpunit.xml.dist

+2-8
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,8 @@
33
colors="true"
44
convertErrorsToExceptions="true"
55
convertNoticesToExceptions="true"
6-
convertWarningsToExceptions="true"
7-
syntaxCheck="true">
6+
convertWarningsToExceptions="true">
87
<testsuite name="transcoder">
9-
<directory>tests</directory>
8+
<directory suffix=".php">tests</directory>
109
</testsuite>
11-
<filter>
12-
<whitelist>
13-
<directory suffix=".php">src/</directory>
14-
</whitelist>
15-
</filter>
1610
</phpunit>

src/Decoder/Bzip2Decoder.php

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
declare(strict_types = 1);
3+
declare(strict_types=1);
44

55
/*
66
* This file is part of the brainbits transcoder package.
@@ -15,38 +15,44 @@
1515

1616
use Brainbits\Transcoder\Exception\DecodeFailedException;
1717

18+
use function bzdecompress;
19+
use function is_string;
20+
1821
/**
1922
* Bzip2 decoder.
2023
*/
2124
class Bzip2Decoder implements DecoderInterface
2225
{
23-
const TYPE = 'bzip2';
26+
public const TYPE = 'bzip2';
2427

2528
public function decode(string $data): string
2629
{
2730
$data = bzdecompress($data);
2831

2932
if ($this->isErrorCode($data)) {
30-
throw new DecodeFailedException("bzdecompress failed.");
33+
throw new DecodeFailedException('bzdecompress failed.');
3134
}
3235

3336
if (!$data) {
34-
throw new DecodeFailedException("bzdecompress returned no data.");
37+
throw new DecodeFailedException('bzdecompress returned no data.');
38+
}
39+
40+
if (!is_string($data)) {
41+
throw new DecodeFailedException('bzdecompress returned error code.');
3542
}
3643

3744
return $data;
3845
}
3946

4047
public function supports(?string $type): bool
4148
{
42-
return self::TYPE === $type;
49+
return $type === self::TYPE;
4350
}
4451

4552
/**
4653
* @param mixed $result
47-
*
48-
* @return bool
4954
*/
55+
// phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
5056
private function isErrorCode($result): bool
5157
{
5258
return $result === -1 || $result === -2 || $result === -3 || $result === -5 || $result === -6 ||

src/Decoder/DecoderInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
declare(strict_types = 1);
3+
declare(strict_types=1);
44

55
/*
66
* This file is part of the brainbits transcoder package.

src/Decoder/DecoderResolver.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
declare(strict_types = 1);
3+
declare(strict_types=1);
44

55
/*
66
* This file is part of the brainbits transcoder package.
@@ -13,23 +13,23 @@
1313

1414
namespace Brainbits\Transcoder\Decoder;
1515

16-
use RuntimeException;
16+
use Brainbits\Transcoder\Exception\RuntimeException;
17+
18+
use function sprintf;
1719

1820
/**
1921
* Decoder resolver.
2022
* Resolves decoders based on supported type.
2123
*/
2224
class DecoderResolver implements DecoderResolverInterface
2325
{
24-
/**
25-
* @var DecoderInterface[]
26-
*/
27-
private $decoders = array();
26+
/** @var DecoderInterface[] */
27+
private array $decoders = [];
2828

2929
/**
3030
* @param DecoderInterface[] $decoders
3131
*/
32-
public function __construct(array $decoders = array())
32+
public function __construct(array $decoders = [])
3333
{
3434
foreach ($decoders as $decoder) {
3535
$this->addDecoder($decoder);
@@ -44,7 +44,7 @@ public function resolve(?string $type): DecoderInterface
4444
}
4545
}
4646

47-
throw new RuntimeException("No decoder supports the requested type $type");
47+
throw new RuntimeException(sprintf('No decoder supports the requested type %s', (string) $type));
4848
}
4949

5050
private function addDecoder(DecoderInterface $decoder): void

src/Decoder/DecoderResolverInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
declare(strict_types = 1);
3+
declare(strict_types=1);
44

55
/*
66
* This file is part of the brainbits transcoder package.

src/Decoder/DeflateDecoder.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
declare(strict_types = 1);
3+
declare(strict_types=1);
44

55
/*
66
* This file is part of the brainbits transcoder package.
@@ -15,26 +15,28 @@
1515

1616
use Brainbits\Transcoder\Exception\DecodeFailedException;
1717

18+
use function gzinflate;
19+
1820
/**
1921
* Deflate decoder.
2022
*/
2123
class DeflateDecoder implements DecoderInterface
2224
{
23-
const TYPE = 'deflate';
25+
public const TYPE = 'deflate';
2426

2527
public function decode(string $data): string
2628
{
2729
$data = gzinflate($data);
2830

2931
if (!$data) {
30-
throw new DecodeFailedException("gzinflate returned no data.");
32+
throw new DecodeFailedException('gzinflate returned no data.');
3133
}
3234

3335
return $data;
3436
}
3537

3638
public function supports(?string $type): bool
3739
{
38-
return self::TYPE === $type;
40+
return $type === self::TYPE;
3941
}
4042
}

src/Decoder/GzipDecoder.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
declare(strict_types = 1);
3+
declare(strict_types=1);
44

55
/*
66
* This file is part of the brainbits transcoder package.
@@ -15,26 +15,28 @@
1515

1616
use Brainbits\Transcoder\Exception\DecodeFailedException;
1717

18+
use function gzdecode;
19+
1820
/**
1921
* Gzip decoder.
2022
*/
2123
class GzipDecoder implements DecoderInterface
2224
{
23-
const TYPE = 'gzip';
25+
public const TYPE = 'gzip';
2426

2527
public function decode(string $data): string
2628
{
2729
$data = gzdecode($data);
2830

2931
if (!$data) {
30-
throw new DecodeFailedException("gzinflate returned no data.");
32+
throw new DecodeFailedException('gzinflate returned no data.');
3133
}
3234

3335
return $data;
3436
}
3537

3638
public function supports(?string $type): bool
3739
{
38-
return self::TYPE === $type;
40+
return $type === self::TYPE;
3941
}
4042
}

src/Decoder/NullDecoder.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
declare(strict_types = 1);
3+
declare(strict_types=1);
44

55
/*
66
* This file is part of the brainbits transcoder package.
@@ -18,7 +18,7 @@
1818
*/
1919
class NullDecoder implements DecoderInterface
2020
{
21-
const TYPE = 'null';
21+
public const TYPE = 'null';
2222

2323
public function decode(string $data): string
2424
{
@@ -27,6 +27,6 @@ public function decode(string $data): string
2727

2828
public function supports(?string $type): bool
2929
{
30-
return null === $type || self::TYPE === $type;
30+
return $type === null || $type === self::TYPE;
3131
}
3232
}

0 commit comments

Comments
 (0)