Skip to content

Commit

Permalink
Refactor to php7
Browse files Browse the repository at this point in the history
  • Loading branch information
maschmann committed Mar 26, 2017
1 parent e5dcaaa commit 96358dd
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 54 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
}
],
"require": {
"php": ">=5.4.0",
"php": ">=7.0.0",
"symfony/yaml": ">=2.7 <=4.0"
},
"require-dev": {
"phpunit/phpunit": "<5.0",
"phpunit/phpunit": "^5.0",
"mikey179/vfsStream": "^1.6"
},
"config": {
Expand Down
24 changes: 12 additions & 12 deletions lib/PhpFlo/Common/DefinitionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);
namespace PhpFlo\Common;

/**
Expand All @@ -20,52 +20,52 @@ interface DefinitionInterface
{
/**
* @param array $definition
* @return $this
* @return DefinitionInterface
*/
public function definition(array $definition);
public function definition(array $definition) : DefinitionInterface;

/**
* @return array
*/
public function properties();
public function properties() : array;

/**
* @return array
*/
public function initializers();
public function initializers() : array;

/**
* @return array
*/
public function processes();
public function processes() : array;

/**
* @return array
*/
public function connections();
public function connections() : array;

/**
* @return array
*/
public function toArray();
public function toArray() : array;

/**
* @return string
*/
public function toJson();
public function toJson() : string;

/**
* @return string
*/
public function toYaml();
public function toYaml() : string;

/**
* @return string
*/
public function toFbp();
public function toFbp() : string;

/**
* @return string
*/
public function name();
public function name() : string;
}
2 changes: 1 addition & 1 deletion lib/PhpFlo/Common/FbpDefinitionsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);
namespace PhpFlo\Common;

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/PhpFlo/Common/LoaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace PhpFlo\Common;

use PhpFlo\Exception\LoaderException;
Expand All @@ -24,5 +25,5 @@ interface LoaderInterface
* @return DefinitionInterface
* @throws LoaderException
*/
public static function load($file);
public static function load(string $file) : DefinitionInterface;
}
24 changes: 12 additions & 12 deletions lib/PhpFlo/Fbp/FbpDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);
namespace PhpFlo\Fbp;

use PhpFlo\Common\DefinitionInterface;
Expand Down Expand Up @@ -47,9 +47,9 @@ public function __construct(array $definition = [])

/**
* @param array $definition
* @return $this
* @return DefinitionInterface
*/
public function definition(array $definition)
public function definition(array $definition) : DefinitionInterface
{
$this->schema = array_replace_recursive(
$this->schema,
Expand All @@ -62,71 +62,71 @@ public function definition(array $definition)
/**
* @return array
*/
public function properties()
public function properties() : array
{
return $this->schema[self::PROPERTIES_LABEL];
}

/**
* @return array
*/
public function initializers()
public function initializers() : array
{
return $this->schema[self::INITIALIZERS_LABEL];
}

/**
* @return array
*/
public function processes()
public function processes() : array
{
return $this->schema[self::PROCESSES_LABEL];
}

/**
* @return array
*/
public function connections()
public function connections() : array
{
return $this->schema[self::CONNECTIONS_LABEL];
}

/**
* @return string
*/
public function name()
public function name() : string
{
return $this->schema[self::PROPERTIES_LABEL]['name'];
}

/**
* @return array
*/
public function toArray()
public function toArray() : array
{
return $this->schema;
}

/**
* @return string
*/
public function toJson()
public function toJson() : string
{
return FbpDumper::toJson($this->schema);
}

/**
* @return string
*/
public function toYaml()
public function toYaml() : string
{
return FbpDumper::toYaml($this->schema);
}

/**
* @return string
*/
public function toFbp()
public function toFbp() : string
{
return FbpDumper::toFbp($this->schema);
}
Expand Down
31 changes: 20 additions & 11 deletions lib/PhpFlo/Fbp/FbpDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);
namespace PhpFlo\Fbp;

use PhpFlo\Common\FbpDefinitionsInterface;
Expand All @@ -31,7 +31,7 @@ final class FbpDumper implements FbpDefinitionsInterface
* @param array $definition
* @return string json
*/
public static function toJson(array $definition)
public static function toJson(array $definition) : string
{
return json_encode($definition, JSON_PRETTY_PRINT);
}
Expand All @@ -41,7 +41,7 @@ public static function toJson(array $definition)
* @param int $inline level until inlining starts
* @return string yaml
*/
public static function toYaml(array $definition, $inline = 3)
public static function toYaml(array $definition, int $inline = 3) : string
{
return Yaml::dump($definition, $inline);
}
Expand All @@ -50,16 +50,17 @@ public static function toYaml(array $definition, $inline = 3)
* @param array $definition
* @return string
*/
public static function toFbp(array $definition)
public static function toFbp(array $definition) : string
{
return self::createFbp($definition);
}

/**
* @param array $definition
* @return string
* @throws DumperException
*/
private static function createFbp(array $definition)
private static function createFbp(array $definition) : string
{
$fbp = [];

Expand Down Expand Up @@ -115,7 +116,7 @@ private static function createFbp(array $definition)
* @param array $connectionTouple
* @return string
*/
private static function examineConnectionTouple(array $connectionTouple)
private static function examineConnectionTouple(array $connectionTouple) : string
{
self::hasElement(self::SOURCE_LABEL, $connectionTouple);
self::hasElement(self::TARGET_LABEL, $connectionTouple);
Expand All @@ -132,7 +133,7 @@ private static function examineConnectionTouple(array $connectionTouple)
* @throws DumperException
* @return string
*/
private static function examineProcess($type, array $processPart)
private static function examineProcess(string $type, array $processPart) : string
{
self::hasElement(self::PROCESS_LABEL, $processPart);
self::hasElement(self::PORT_LABEL, $processPart);
Expand Down Expand Up @@ -163,8 +164,11 @@ private static function examineProcess($type, array $processPart)
* @param bool $triggerException
* @return bool
*/
private static function hasElement($needle, array $haystack, $triggerException = true)
{
private static function hasElement(
string $needle,
array $haystack,
bool $triggerException = true
) : bool {
if (empty($haystack[$needle])) {
if ($triggerException) {
self::throwDumperException('elmeent', $needle);
Expand All @@ -181,7 +185,7 @@ private static function hasElement($needle, array $haystack, $triggerException =
* @param string $targetPort
* @return string
*/
private static function connectPorts($sourcePort, $targetPort)
private static function connectPorts(string $sourcePort, string $targetPort) : string
{
return implode(
" " . self::SOURCE_TARGET_SEPARATOR . " ",
Expand All @@ -192,7 +196,12 @@ private static function connectPorts($sourcePort, $targetPort)
);
}

private static function throwDumperException($type, $value)
/**
* @param string $type
* @param string $value
* @throws DumperException
*/
private static function throwDumperException(string $type, string $value)
{
switch ($type) {
case 'element':
Expand Down
Loading

0 comments on commit 96358dd

Please sign in to comment.