Skip to content

Commit

Permalink
Add PSR-11, loads of types, start fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
maschmann committed Mar 23, 2017
1 parent c7a9812 commit 259ee81
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 98 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"php": ">=7.0.0",
"evenement/evenement": "^2.0",
"phpflo/phpflo-core": "^1.0",
"phpflo/phpflo-fbp": "^1.0"
"phpflo/phpflo-fbp": "^1.0",
"psr/container": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^5.0"
Expand Down
6 changes: 3 additions & 3 deletions lib/PhpFlo/Builder/ComponentDiFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use PhpFlo\Common\ComponentBuilderInterface;
use PhpFlo\Common\ComponentInterface;
use PhpFlo\Exception\InvalidDefinitionException;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Psr\Container\ContainerInterface;

/**
* Example of how to use a depency injection container with builder.
Expand All @@ -35,7 +35,7 @@ class ComponentDiFinder implements ComponentBuilderInterface
*
* @param ContainerInterface $container dependency injection container
*/
public function __construct($container)
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
Expand All @@ -45,7 +45,7 @@ public function __construct($container)
* @return ComponentInterface
* @throws InvalidDefinitionException
*/
public function build($component)
public function build(string $component) : ComponentInterface
{
$instance = $this->container->get($component);

Expand Down
2 changes: 1 addition & 1 deletion lib/PhpFlo/Builder/ComponentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ComponentFactory implements ComponentBuilderInterface
* @return ComponentInterface
* @throws InvalidDefinitionException
*/
public function build($component)
public function build(string $component) : ComponentInterface
{
if (!class_exists($component) && strpos($component, '\\') === false) {
$component = "PhpFlo\\Component\\{$component}";
Expand Down
8 changes: 4 additions & 4 deletions lib/PhpFlo/Common/NetworkInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ public function getNode(string $id);

/**
* @param array $edge
* @return $this
* @return NetworkInterface
*/
public function removeEdge(array $edge);
public function removeEdge(array $edge) : NetworkInterface;

/**
* @param array $node
* @return $this
* @return NetworkInterface
*/
public function removeNode(array $node);
public function removeNode(array $node) : NetworkInterface;

/**
* Add initialization data
Expand Down
11 changes: 5 additions & 6 deletions lib/PhpFlo/Common/PortInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PhpFlo\Common;

use PhpFlo\Exception\InvalidDefinitionException;
Expand Down Expand Up @@ -47,14 +46,14 @@ public function getAttribute(string $name);
/**
* @return string
*/
public function getName();
public function getName() : string;

/**
* @param SocketInterface $socket
* @throws InvalidDefinitionException
* @return $this
* @return PortInterface
*/
public function attach(SocketInterface $socket);
public function attach(SocketInterface $socket) : PortInterface;

/**
* @param mixed $data
Expand Down Expand Up @@ -97,14 +96,14 @@ public function disconnect();
/**
* @return bool
*/
public function isConnected();
public function isConnected() : bool;

/**
* Checks if port is attached.
*
* @return bool
*/
public function isAttached();
public function isAttached() : bool;

/**
* @param string $groupName
Expand Down
6 changes: 3 additions & 3 deletions lib/PhpFlo/ComponentRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct()
* @return ComponentInterface
* @throws ComponentNotFoundException
*/
public function get($alias)
public function get(string $alias) : ComponentInterface
{
if (array_key_exists($alias, $this->references)) {
return $this->references[$alias];
Expand All @@ -50,10 +50,10 @@ public function get($alias)
/**
* @param ComponentInterface $component
* @param string $alias
* @return $this
* @return ComponentRegistryInterface
* @throws ComponentException
*/
public function add(ComponentInterface $component, $alias)
public function add(ComponentInterface $component, string $alias) : ComponentRegistryInterface
{
if (!array_key_exists($alias, $this->references)) {
$this->references[$alias] = $component;
Expand Down
44 changes: 24 additions & 20 deletions lib/PhpFlo/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public function __construct(DefinitionInterface $definition)
/**
* @param string $id
* @param string $component
* @return $this
* @return Graph
*/
public function addNode($id, $component)
public function addNode(string $id, string $component) : Graph
{
$node = [
NetworkInterface::NODE_ID => $id,
Expand All @@ -82,9 +82,9 @@ public function addNode($id, $component)

/**
* @param string $id
* @return $this
* @return Graph
*/
public function removeNode($id)
public function removeNode(string $id) : Graph
{
foreach ($this->edges as $edge) {
if ($edge[NetworkInterface::SOURCE][NetworkInterface::NODE] == $id) {
Expand Down Expand Up @@ -112,7 +112,7 @@ public function removeNode($id)
* @param string $id
* @return mixed|null
*/
public function getNode($id)
public function getNode(string $id)
{
if (!isset($this->nodes[$id])) {
return null;
Expand All @@ -126,10 +126,14 @@ public function getNode($id)
* @param string $outPort
* @param string $inNode
* @param string $inPort
* @return $this
* @return Graph
*/
public function addEdge($outNode, $outPort, $inNode, $inPort)
{
public function addEdge(
string $outNode,
string $outPort,
string $inNode,
string $inPort
) : Graph {
$edge = [
NetworkInterface::SOURCE => [
NetworkInterface::NODE => $outNode,
Expand All @@ -150,9 +154,9 @@ public function addEdge($outNode, $outPort, $inNode, $inPort)
/**
* @param string $node
* @param string $port
* @return $this
* @return Graph
*/
public function removeEdge($node, $port)
public function removeEdge(string $node, string $port) : Graph
{
foreach ($this->edges as $index => $edge) {
if ($edge[NetworkInterface::SOURCE][NetworkInterface::NODE] == $node
Expand Down Expand Up @@ -186,9 +190,9 @@ public function removeEdge($node, $port)
* @param mixed $data
* @param string $node
* @param string $port
* @return $this
* @return Graph
*/
public function addInitial($data, $node, $port)
public function addInitial($data, string $node, string $port) : Graph
{
$initializer = [
NetworkInterface::SOURCE => [
Expand All @@ -209,23 +213,23 @@ public function addInitial($data, $node, $port)
/**
* @return string
*/
public function toFbp()
public function toFbp() : string
{
return $this->definition->toFbp();
}

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

/**
* @return string
*/
public function toJson()
public function toJson() : string
{
return $this->definition->toJson();
}
Expand All @@ -236,7 +240,7 @@ public function toJson()
* @param string $file
* @return bool
*/
public function save($file)
public function save(string $file) : bool
{
$stat = file_put_contents($file, $this->definition->toFbp());

Expand All @@ -254,7 +258,7 @@ public function save($file)
* @throws InvalidDefinitionException
* @return Graph
*/
public static function loadString($string)
public static function loadString(string $string) : Graph
{
$loader = new FbpParser($string);
$definition = $loader->run();
Expand All @@ -269,7 +273,7 @@ public static function loadString($string)
* @throws InvalidDefinitionException
* @return Graph
*/
public static function loadFile($file)
public static function loadFile(string $file) : Graph
{
return self::loadDefinition(
Loader::load($file)
Expand All @@ -280,9 +284,9 @@ public static function loadFile($file)
* Load PhpFlo graph definition.
*
* @param DefinitionInterface $definition
* @return \PhpFlo\Graph
* @return Graph
*/
public static function loadDefinition(DefinitionInterface $definition)
public static function loadDefinition(DefinitionInterface $definition) : Graph
{
$graph = new Graph($definition);

Expand Down
12 changes: 6 additions & 6 deletions lib/PhpFlo/Interaction/AbstractPort.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class AbstractPort extends EventEmitter
* @param string $name
* @param array $attributes
*/
public function __construct($name, array $attributes)
public function __construct(string $name, array $attributes)
{
$defaultAttributes = [
'datatype' => 'all',
Expand All @@ -86,7 +86,7 @@ public function __construct($name, array $attributes)
* @param string $toType
* @return bool
*/
public static function isCompatible($fromType, $toType)
public static function isCompatible(string $fromType, string $toType) : bool
{
switch(true) {
case (($fromType == $toType) || ($toType == 'all' || $toType == 'bang')):
Expand Down Expand Up @@ -126,7 +126,7 @@ public function onDetach()
/**
* @return array
*/
public function getAttributes()
public function getAttributes() : array
{
return $this->attributes;
}
Expand All @@ -135,7 +135,7 @@ public function getAttributes()
* @param string $name
* @return mixed|null
*/
public function getAttribute($name)
public function getAttribute(string $name)
{
$attribute = null;

Expand All @@ -149,9 +149,9 @@ public function getAttribute($name)
/**
* @return string
*/
public function getName()
public function getName() : string
{
return $this->name;
return (string)$this->name;
}

/**
Expand Down
Loading

0 comments on commit 259ee81

Please sign in to comment.