Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
javer committed Oct 30, 2019
1 parent ffa39e3 commit 3f36052
Show file tree
Hide file tree
Showing 21 changed files with 188 additions and 123 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
/composer.phar
/phpunit.xml
/vendor/
/.phpcs-cache
/phpcs.xml
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ language: php
php:
- 7.1
- 7.2
- 7.3
- 7.4snapshot

before_script: composer install -n --dev

script: vendor/bin/phpunit --coverage-text
script:
- vendor/bin/phpcs
- vendor/bin/phpunit --coverage-text

allow_failures:
- php: 7.4snapshot
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"php-ffmpeg/php-ffmpeg": ">=0.7"
},
"require-dev": {
"phpunit/phpunit": "^7.0"
"phpunit/phpunit": "^7.0",
"squizlabs/php_codesniffer": "3.5.*",
"swivl/php-coding-standard": "^1.0"
},
"autoload": {
"psr-4": {
Expand All @@ -31,7 +33,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
"dev-master": "1.1.x-dev"
}
}
}
19 changes: 19 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd" name="FFmpeg transformer">
<arg name="basepath" value="."/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>
<arg value="p"/>
<arg name="extensions" value="php"/>
<arg name="tab-width" value="4"/>
<arg name="report-width" value="120"/>

<file>src/</file>
<file>tests/</file>

<rule ref="vendor/swivl/php-coding-standard/Swivl/ruleset.xml">
<exclude name="PSR12.ControlStructures.ControlStructureSpacing.FirstExpressionLine"/>
<exclude name="PSR12.ControlStructures.ControlStructureSpacing.CloseParenthesisLine"/>
</rule>
</ruleset>
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<phpunit bootstrap="./vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="FFMpeg Command Test Suite">
<testsuite name="FFMpeg transformer Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
Expand Down
11 changes: 6 additions & 5 deletions src/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Javer\FfmpegTransformer\File\File;
use Javer\FfmpegTransformer\File\FileInterface;
use LogicException;

/**
* Class Command
Expand Down Expand Up @@ -51,18 +52,18 @@ public function addOption(string $name, string $argument = ''): CommandInterface
*
* @return array
*
* @throws \LogicException
* @throws LogicException
*/
public function build(): array
{
$options = $this->options;

if (count($this->inputFiles) == 0) {
throw new \LogicException('You should specify at least one input file');
if (count($this->inputFiles) === 0) {
throw new LogicException('You should specify at least one input file');
}

if (count($this->outputFiles) == 0) {
throw new \LogicException('You should specify at least one output file');
if (count($this->outputFiles) === 0) {
throw new LogicException('You should specify at least one output file');
}

foreach ($this->inputFiles as $inputFile) {
Expand Down
47 changes: 24 additions & 23 deletions src/File/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Javer\FfmpegTransformer\Stream\StreamInterface;
use Javer\FfmpegTransformer\Stream\VideoStream;
use Javer\FfmpegTransformer\Stream\VideoStreamInterface;
use LogicException;

/**
* Class File
Expand Down Expand Up @@ -56,7 +57,7 @@ class File implements FileInterface
/**
* @var FilterGraphInterface
*/
protected $filterGraph = null;
protected $filterGraph;

/**
* @var integer
Expand Down Expand Up @@ -395,12 +396,12 @@ public function profile(string $profile): FileInterface
*
* @return FileInterface
*
* @throws \LogicException
* @throws LogicException
*/
public function attach(string $fiename): FileInterface
{
if ($this->isInput) {
throw new \LogicException('Attach option can be used only for output files');
throw new LogicException('Attach option can be used only for output files');
}

return $this->addOption('-attach', $fiename);
Expand All @@ -411,12 +412,12 @@ public function attach(string $fiename): FileInterface
*
* @return FileInterface
*
* @throws \LogicException
* @throws LogicException
*/
public function moveHeaderToStart(): FileInterface
{
if ($this->isInput) {
throw new \LogicException('Movflags option can be used only for output files');
throw new LogicException('Movflags option can be used only for output files');
}

return $this->addOption('-movflags', 'faststart');
Expand All @@ -443,12 +444,12 @@ public function loop(bool $flag = true): FileInterface
*
* @return VideoStreamInterface
*
* @throws \LogicException
* @throws LogicException
*/
public function addVideoStream(VideoStreamInterface $mapVideoStream = null): VideoStreamInterface
{
if ($this->isInput) {
throw new \LogicException('AddVideoStream can be used only for output files, use getVideoStream for input');
throw new LogicException('AddVideoStream can be used only for output files, use getVideoStream for input');
}

$videoStream = new VideoStream($this);
Expand All @@ -469,12 +470,12 @@ public function addVideoStream(VideoStreamInterface $mapVideoStream = null): Vid
*
* @return AudioStreamInterface
*
* @throws \LogicException
* @throws LogicException
*/
public function addAudioStream(AudioStreamInterface $mapAudioStream = null): AudioStreamInterface
{
if ($this->isInput) {
throw new \LogicException('AddAudioStream can be used only for output files, use getAudioStream for input');
throw new LogicException('AddAudioStream can be used only for output files, use getAudioStream for input');
}

$audioStream = new AudioStream($this);
Expand Down Expand Up @@ -525,12 +526,12 @@ public function getAudioStream(int $number = 0): AudioStreamInterface
*
* @return VideoStreamInterface
*
* @throws \LogicException
* @throws LogicException
*/
public function createVideoStream(): VideoStreamInterface
{
if ($this->isInput) {
throw new \LogicException('CreateVideoStream can only be used for output files');
throw new LogicException('CreateVideoStream can only be used for output files');
}

$streamName = sprintf('v%s_%d', $this->getName(), $this->streamsCounter++);
Expand All @@ -543,12 +544,12 @@ public function createVideoStream(): VideoStreamInterface
*
* @return AudioStreamInterface
*
* @throws \LogicException
* @throws LogicException
*/
public function createAudioStream(): AudioStreamInterface
{
if ($this->isInput) {
throw new \LogicException('CreateAudioStream can only be used for output files');
throw new LogicException('CreateAudioStream can only be used for output files');
}

$streamName = sprintf('a%s_%d', $this->getName(), $this->streamsCounter++);
Expand All @@ -563,7 +564,7 @@ public function createAudioStream(): AudioStreamInterface
*
* @return StreamInterface
*
* @throws \LogicException
* @throws LogicException
*/
public function createStream(string $type): StreamInterface
{
Expand All @@ -575,7 +576,7 @@ public function createStream(string $type): StreamInterface
return $this->createAudioStream();

default:
throw new \LogicException(sprintf('Unknown stream type: %s', $type));
throw new LogicException(sprintf('Unknown stream type: %s', $type));
}
}

Expand All @@ -586,7 +587,7 @@ public function createStream(string $type): StreamInterface
*
* @return integer|null
*
* @throws \LogicException
* @throws LogicException
*/
public function getStreamNumber(StreamInterface $stream): ?int
{
Expand All @@ -602,7 +603,7 @@ public function getStreamNumber(StreamInterface $stream): ?int
break;

default:
throw new \LogicException(sprintf('Unknown stream type: %s', $stream->getType()));
throw new LogicException(sprintf('Unknown stream type: %s', $stream->getType()));
}

return $streamNumber === false ? null : $streamNumber;
Expand All @@ -616,18 +617,18 @@ public function getStreamNumber(StreamInterface $stream): ?int
*
* @return FileInterface
*
* @throws \LogicException
* @throws LogicException
*/
public function moveStreamToPosition(StreamInterface $stream, int $position): FileInterface
{
if ($stream->getInput()) {
throw new \LogicException('You cannot reorder streams in the input file');
throw new LogicException('You cannot reorder streams in the input file');
}

$streamNumber = $this->getStreamNumber($stream);

if (is_null($streamNumber)) {
throw new \LogicException(sprintf('Stream %s not found', $stream->getName()));
if ($streamNumber === null) {
throw new LogicException(sprintf('Stream %s not found', $stream->getName()));
}

switch ($stream->getType()) {
Expand All @@ -642,7 +643,7 @@ public function moveStreamToPosition(StreamInterface $stream, int $position): Fi
break;

default:
throw new \LogicException(sprintf('Unknown stream type: %s', $stream->getType()));
throw new LogicException(sprintf('Unknown stream type: %s', $stream->getType()));
}

return $this;
Expand Down Expand Up @@ -679,7 +680,7 @@ public function removeStream(StreamInterface $stream): FileInterface
*/
public function filter(): FilterGraphInterface
{
if (is_null($this->filterGraph)) {
if ($this->filterGraph === null) {
$this->filterGraph = new FilterGraph($this);
}

Expand Down
6 changes: 4 additions & 2 deletions src/Filter/Chain/AudioFilterChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Javer\FfmpegTransformer\Filter\Chain;

use InvalidArgumentException;

/**
* Class AudioFilterChain
*
Expand All @@ -16,12 +18,12 @@ class AudioFilterChain extends FilterChain implements AudioFilterChainInterface
*
* @return AudioFilterChainInterface
*
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
*/
public function channelsplit(array $arguments = []): AudioFilterChainInterface
{
if (!isset($arguments['channel_layout'])) {
throw new \InvalidArgumentException('You must specify channel_layout for the channelsplit filter');
throw new InvalidArgumentException('You must specify channel_layout for the channelsplit filter');
}

switch ($arguments['channel_layout']) {
Expand Down
7 changes: 4 additions & 3 deletions src/Filter/Chain/ComplexFilterChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Javer\FfmpegTransformer\Stream\AudioStreamInterface;
use Javer\FfmpegTransformer\Stream\StreamInterface;
use Javer\FfmpegTransformer\Stream\VideoStreamInterface;
use LogicException;

/**
* Class ComplexFilterChain
Expand All @@ -18,7 +19,7 @@ class ComplexFilterChain extends FilterChain implements ComplexFilterChainInterf
*
* @return ComplexFilterChainInterface
*
* @throws \LogicException
* @throws LogicException
*/
public function concat(): ComplexFilterChainInterface
{
Expand All @@ -30,8 +31,8 @@ public function concat(): ComplexFilterChainInterface
$partsCount = min($videoCount, $audioCount);
}

if ($videoCount % $partsCount != 0 || $audioCount % $partsCount != 0) {
throw new \LogicException('All segments must have the same number of streams of each type');
if ($videoCount % $partsCount !== 0 || $audioCount % $partsCount !== 0) {
throw new LogicException('All segments must have the same number of streams of each type');
}

$videoCount /= $partsCount;
Expand Down
Loading

0 comments on commit 3f36052

Please sign in to comment.