Skip to content

Commit f8bbed9

Browse files
committed
fix: fix phpstan and phpcs errors
1 parent e508e8e commit f8bbed9

23 files changed

+104
-76
lines changed

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
}

src/Decoder/SevenzDecoder.php

+5-5
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.
@@ -21,9 +21,9 @@
2121
*/
2222
class SevenzDecoder implements DecoderInterface
2323
{
24-
const TYPE = '7z';
24+
public const TYPE = '7z';
2525

26-
private $executable;
26+
private string $executable;
2727

2828
public function __construct(string $executable = '7z')
2929
{
@@ -41,7 +41,7 @@ public function decode(string $data): string
4141
$process->run();
4242

4343
if (!$process->isSuccessful()) {
44-
throw new DecodeFailedException('7z failure: '.$process->getOutput().$process->getErrorOutput());
44+
throw new DecodeFailedException('7z failure: ' . $process->getOutput() . $process->getErrorOutput());
4545
}
4646

4747
$data = $process->getOutput();
@@ -51,7 +51,7 @@ public function decode(string $data): string
5151

5252
public function supports(?string $type): bool
5353
{
54-
return self::TYPE === $type;
54+
return $type === self::TYPE;
5555
}
5656

5757
private function getProcess(string $data): Process

src/Encoder/Bzip2Encoder.php

+11-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,33 @@
1515

1616
use Brainbits\Transcoder\Exception\EncodeFailedException;
1717

18+
use function bzcompress;
19+
use function is_string;
20+
1821
/**
1922
* bzip2 encoder.
2023
*/
2124
class Bzip2Encoder implements EncoderInterface
2225
{
23-
const TYPE = 'bzip2';
26+
public const TYPE = 'bzip2';
2427

2528
public function encode(string $data): string
2629
{
2730
$data = bzcompress($data, 9);
2831

2932
if (!$data) {
30-
throw new EncodeFailedException("bzcompress returned no data.");
33+
throw new EncodeFailedException('bzcompress returned no data.');
34+
}
35+
36+
if (!is_string($data)) {
37+
throw new EncodeFailedException('bzdecompress returned error code.');
3138
}
3239

3340
return $data;
3441
}
3542

3643
public function supports(?string $type): bool
3744
{
38-
return self::TYPE === $type;
45+
return $type === self::TYPE;
3946
}
4047
}

src/Encoder/DeflateEncoder.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\EncodeFailedException;
1717

18+
use function gzdeflate;
19+
1820
/**
1921
* deflate encoder.
2022
*/
2123
class DeflateEncoder implements EncoderInterface
2224
{
23-
const TYPE = 'deflate';
25+
public const TYPE = 'deflate';
2426

2527
public function encode(string $data): string
2628
{
2729
$data = gzdeflate($data, 9);
2830

2931
if (!$data) {
30-
throw new EncodeFailedException("gzdeflate returned no data.");
32+
throw new EncodeFailedException('gzdeflate 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/Encoder/EncoderInterface.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.

0 commit comments

Comments
 (0)