Skip to content

Commit

Permalink
Apply rectorphp and php-cs-fixer to example and test
Browse files Browse the repository at this point in the history
  • Loading branch information
stevleibelt committed Jul 29, 2024
1 parent 261b0b6 commit 127968c
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 40 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]


### Added

* Added rector
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ After code changes, please run:
```bash
composer check
./vendor/bin/rector process
./vendor/bin/php-cs-fixer fix example
./vendor/bin/php-cs-fixer fix source
./vendor/bin/php-cs-fixer fix test
```

## Links
Expand Down
10 changes: 3 additions & 7 deletions example/DataFlowManipulator/run.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ class StringProcess implements ExecutableInterface
*/
public function execute($input = null)
{
$input .= PHP_EOL . __METHOD__;

return $input;
return $input . (PHP_EOL . __METHOD__);
}
}

Expand All @@ -62,7 +60,6 @@ class DataFlowManipulator implements ExecutableInterface
private $stringProcess;

/**
* @param ArrayProcess $process
* @return $this
*/
public function setArrayProcess(ArrayProcess $process)
Expand All @@ -73,7 +70,6 @@ public function setArrayProcess(ArrayProcess $process)
}

/**
* @param StringProcess $process
* @return $this
*/
public function setStringProcess(StringProcess $process)
Expand All @@ -92,7 +88,7 @@ public function execute($input = null)
{
if (is_array($input)) {
return $this->arrayProcess->execute($input);
} else if (is_string($input)) {
} elseif (is_string($input)) {
return $this->stringProcess->execute($input);
} else {
throw new ExecutableException('input must be from type of array or string');
Expand All @@ -110,6 +106,6 @@ public function execute($input = null)
echo 'string' . PHP_EOL;
echo var_export($output, true) . PHP_EOL;

$output = $pipe->execute(array('Hello World'));
$output = $pipe->execute(['Hello World']);
echo 'array' . PHP_EOL;
echo var_export($output, true) . PHP_EOL;
5 changes: 2 additions & 3 deletions example/FailingExecution/run.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @author stev leibelt <[email protected]>
* @since 2014-11-08
* @since 2014-11-08
*/

namespace Example\FailingExecution;
Expand Down Expand Up @@ -35,10 +35,9 @@ class ProcessTwo implements ExecutableInterface
{
/**
* @param mixed $input
* @return mixed
* @throws \Net\Bazzline\Component\ProcessPipe\ExecutableException
*/
public function execute($input = null)
public function execute($input = null): never
{
throw new ExecutableException(__METHOD__ . ' has failed');
}
Expand Down
8 changes: 2 additions & 6 deletions example/InputArray/run.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @author stev leibelt <[email protected]>
* @since 2014-11-08
* @since 2014-11-08
*/

namespace Example\InputArray;
Expand Down Expand Up @@ -51,11 +51,7 @@ public function execute($input = null)
}
}

$input = array(
'name' => 'foo',
'steps' => array(),
'times' => array()
);
$input = ['name' => 'foo', 'steps' => [], 'times' => []];
$pipe = new Pipe();

$pipe->pipe(
Expand Down
17 changes: 3 additions & 14 deletions example/InputGenerator/run.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @author stev leibelt <[email protected]>
* @since 2014-11-08
* @since 2014-11-08
*/

namespace Example\InputGenerator;
Expand All @@ -23,14 +23,7 @@ class DataGeneratorProcess implements ExecutableInterface
*/
public function execute($input = null)
{
$input = array();
$input[] = array(
microtime(true),
'debug',
'new generated log data'
);

return $input;
return [[microtime(true), 'debug', 'new generated log data']];
}
}

Expand All @@ -46,11 +39,7 @@ class ProcessTwo implements ExecutableInterface
*/
public function execute($input = null)
{
$input[] = array(
microtime(true),
'debug',
'hello world'
);
$input[] = [microtime(true), 'debug', 'hello world'];

return $input;
}
Expand Down
4 changes: 2 additions & 2 deletions example/InputTransformer/run.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @author stev leibelt <[email protected]>
* @since 2014-11-08
* @since 2014-11-08
*/

namespace Example\InputTransformer;
Expand Down Expand Up @@ -29,7 +29,7 @@ public function execute($input = null)
throw new ExecutableException('input must be instance of object');
}

$array = array();
$array = [];

foreach (get_object_vars($input) as $property => $value) {
$array[$property] = $value;
Expand Down
4 changes: 1 addition & 3 deletions example/InputValidator/run.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ class ProcessOne implements ExecutableInterface
*/
public function execute($input = null)
{
$input .= ' ' . __METHOD__;

return $input;
return $input . (' ' . __METHOD__);
}
}

Expand Down
2 changes: 1 addition & 1 deletion example/NoInput/run.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @author stev leibelt <[email protected]>
* @since 2014-11-08
* @since 2014-11-08
*/

namespace Example\NoInput;
Expand Down
4 changes: 3 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

return RectorConfig::configure()
->withPaths([
__DIR__ . '/source'
__DIR__ . '/example',
__DIR__ . '/source',
__DIR__ . '/test'
])
// uncomment to reach your current PHP version
->withPhpSets(php83: true)
Expand Down
2 changes: 1 addition & 1 deletion test/PipeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function testExecuteWithFailingProcess()

$process->shouldReceive('execute')
->once()
->andThrow('Net\Bazzline\Component\ProcessPipe\ExecutableException', 'unit test');
->andThrow(\Net\Bazzline\Component\ProcessPipe\ExecutableException::class, 'unit test');

$pipe->pipe($process);
$pipe->execute();
Expand Down
2 changes: 1 addition & 1 deletion test/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function tearDown()
*/
protected function getMockOfProcess()
{
return Mockery::mock('Net\Bazzline\Component\ProcessPipe\ExecutableInterface');
return Mockery::mock(\Net\Bazzline\Component\ProcessPipe\ExecutableInterface::class);
}

/**
Expand Down

0 comments on commit 127968c

Please sign in to comment.