Skip to content

Commit

Permalink
Fix docblocks var and return types. Add missing type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
munkie committed Sep 20, 2015
1 parent db00d24 commit ff55f28
Show file tree
Hide file tree
Showing 20 changed files with 121 additions and 69 deletions.
4 changes: 2 additions & 2 deletions src/Nelmio/Alice/Fixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function addProcessor(ProcessorInterface $processor)
$this->processors[] = $processor;
}

protected function persist($persister, $objects)
protected function persist(PersisterInterface $persister, $objects)
{
foreach ($this->processors as $proc) {
foreach ($objects as $obj) {
Expand Down Expand Up @@ -249,7 +249,7 @@ private function validateOptions(array $options)
if (false === is_object($provider) && false === is_string($provider)) {
throw new \InvalidArgumentException(sprintf(
'The provider should be a string or an object, got %s instead',
is_scalar($provider) ?$provider :gettype($provider)
is_scalar($provider) ? $provider : gettype($provider)
));
}
}
Expand Down
13 changes: 10 additions & 3 deletions src/Nelmio/Alice/Fixtures/Builder/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,23 @@

use InvalidArgumentException;
use Nelmio\Alice\Fixtures\Builder\Methods\MethodInterface;
use Nelmio\Alice\Fixtures\Fixture;

class Builder
{
/**
* @var array
**/
* @var MethodInterface[]
*/
protected $methods;

/**
* @var array
*/
protected $templates;

/**
* @param MethodInterface[] $methods
*/
public function __construct(array $methods)
{
foreach ($methods as $method) {
Expand All @@ -51,7 +55,10 @@ public function addBuilder(MethodInterface $builder)
/**
* builds a single fixture from a "raw" definition
*
* @param array $rawData
* @param string $class
* @param string $name
* @param array $spec
* @return Fixture[]
*/
public function build($class, $name, array $spec)
{
Expand Down
14 changes: 8 additions & 6 deletions src/Nelmio/Alice/Fixtures/Builder/Methods/MethodInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,25 @@

namespace Nelmio\Alice\Fixtures\Builder\Methods;

use Nelmio\Alice\Fixtures\Fixture;

interface MethodInterface
{
/**
* tests whether this class can build an fixture with the given name
*
* @param string $name
* @return boolean
* @param string $name
* @return bool
*/
public function canBuild($name);

/**
* builds an fixture from the given class, name, and spec
*
* @param string $class
* @param string $name
* @param array $spec
* @return array
* @param string $class
* @param string $name
* @param array $spec
* @return Fixture[]
*/
public function build($class, $name, array $spec);
}
27 changes: 18 additions & 9 deletions src/Nelmio/Alice/Fixtures/Fixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Fixture
protected $spec;

/**
* @var array
* @var PropertyDefinition[]
*/
protected $properties;

Expand Down Expand Up @@ -164,11 +164,16 @@ public function getName()
/**
* returns the list of properties with the complex properties (__construct, __set, etc) filtered out
*
* @return array
* @return PropertyDefinition[]
*/
public function getProperties()
{
return array_filter($this->properties, function ($property) { return $property->isBasic(); });
return array_filter(
$this->properties,
function (PropertyDefinition $property) {
return $property->isBasic();
}
);
}

/**
Expand All @@ -184,7 +189,8 @@ public function getClassFlags()
/**
* returns true if this fixture has the given class flag
*
* @return boolean
* @param string $flag
* @return bool
*/
public function hasClassFlag($flag)
{
Expand All @@ -204,7 +210,8 @@ public function getNameFlags()
/**
* returns true if this fixture has the given name flag
*
* @return boolean
* @param string $flag
* @return bool
*/
public function hasNameFlag($flag)
{
Expand Down Expand Up @@ -266,7 +273,7 @@ public function hasCustomSetter()
/**
* returns the name of the method to use as the custom setter
*
* @return string
* @return PropertyDefinition
*/
public function getCustomSetter()
{
Expand All @@ -287,7 +294,8 @@ public function setPropertyValue($property, $value)
/**
* returns the value of a property that has been registered as set
*
* @return mixed $value
* @param string $property
* @return mixed
*/
public function getPropertyValue($property)
{
Expand Down Expand Up @@ -315,8 +323,9 @@ public function __toString()
/**
* creates and adds a PropertyDefinition to the fixture with the given name and value
*
* @param string $name
* @param mixed $value
* @param string $name
* @param mixed $value
* @return PropertyDefinition
*/
protected function addProperty($name, $value)
{
Expand Down
49 changes: 28 additions & 21 deletions src/Nelmio/Alice/Fixtures/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@

namespace Nelmio\Alice\Fixtures;

use Nelmio\Alice\Instances\Processor\Methods\Faker;
use Nelmio\Alice\Fixtures\ParameterBag;
use Psr\Log\LoggerInterface;
use Nelmio\Alice\PersisterInterface;
use Nelmio\Alice\Instances\Collection;
use Nelmio\Alice\Instances\Instantiator;
use Nelmio\Alice\Instances\Populator;
use Nelmio\Alice\Instances\Processor;
use Nelmio\Alice\Instances\Processor\Methods\Faker;
use Nelmio\Alice\Instances\Processor\Providers\IdentityProvider;
use Nelmio\Alice\PersisterInterface;
use Nelmio\Alice\Util\TypeHintChecker;
use Psr\Log\LoggerInterface;

/**
* Loads fixtures from an array or file
Expand All @@ -38,12 +37,17 @@ class Loader
protected $typeHintChecker;

/**
* @var Parser
* @var Processor\Processor
*/
protected $processor;

/**
* @var Parser\Parser
**/
protected $parser;

/**
* @var Builder
* @var Builder\Builder
*/
protected $builder;

Expand All @@ -53,12 +57,12 @@ class Loader
protected $fakerProcessorMethod;

/**
* @var Instantiator
* @var Instantiator\Instantiator
*/
protected $instantiator;

/**
* @var Populator
* @var Populator\Populator
*/
protected $populator;

Expand All @@ -68,7 +72,7 @@ class Loader
protected $manager;

/**
* @var \Nelmio\Alice\Fixtures\ParameterBag
* @var ParameterBag
*/
protected $parameterBag;

Expand Down Expand Up @@ -125,7 +129,8 @@ public function __construct($locale = 'en_US', array $providers = [], $seed = 1,
/**
* Loads a fixture file
*
* @param string|array $dataOrFilename data array or filename
* @param string|array $dataOrFilename data array or filename
* @return object[]
*/
public function load($dataOrFilename)
{
Expand Down Expand Up @@ -157,7 +162,7 @@ public function getReference($name, $property = null)
/**
* Returns all references created by the loader
*
* @return array[object]
* @return object[]
*/
public function getReferences()
{
Expand All @@ -181,12 +186,14 @@ public function addProvider($provider)
}

/**
* @param array $references
* References are objects which the loader is aware of while loading fixtures.
*
* @param object[] $references Array of object where the key is the name of the reference
*/
public function setReferences(array $objects)
public function setReferences(array $references)
{
$this->objects->clear();
foreach ($objects as $name => $object) {
foreach ($references as $name => $object) {
$this->objects->set($name, $object);
}
}
Expand Down Expand Up @@ -244,8 +251,8 @@ public function addPopulator(Populator\Methods\MethodInterface $populator)
/**
* parses a file at the given filename
*
* @param string filename
* @return array data
* @param string $filename
* @return array data
*/
protected function parseFile($filename)
{
Expand All @@ -255,8 +262,8 @@ protected function parseFile($filename)
/**
* builds a collection of fixtures
*
* @param array $rawData
* @return array
* @param array $rawData
* @return Fixture[]
*/
protected function buildFixtures(array $rawData)
{
Expand All @@ -275,7 +282,7 @@ protected function buildFixtures(array $rawData)
/**
* creates an empty instance for each fixture, and adds it to our object collection
*
* @param array $fixtures
* @param Fixture[] $fixtures
*/
protected function instantiateFixtures(array $fixtures)
{
Expand All @@ -290,8 +297,8 @@ protected function instantiateFixtures(array $fixtures)
/**
* hydrates each instance described by fixtures and returns the final non-local list
*
* @param array $fixtures
* @return array
* @param Fixture[] $fixtures
* @return object[] List of object created
*/
protected function populateObjects(array $fixtures)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Nelmio/Alice/Fixtures/ParameterBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public function get($key)
}

/**
* @param mixed $value
* @param string $key
* @param mixed $value
*/
public function set($key, $value)
{
Expand Down
8 changes: 6 additions & 2 deletions src/Nelmio/Alice/Fixtures/Parser/Methods/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ protected function compilePhp($file)
return ob_get_clean();
}

/**
* @return \Closure|void
*/
protected function createFakerClosure()
{
if (!$this->context instanceof Loader) {
Expand Down Expand Up @@ -100,8 +103,9 @@ protected function processIncludes($data, $filename)
}

/**
* @param array $data
* @param array $includeData
* @param array $data
* @param array $includeData
* @return array
*/
protected function mergeIncludeData($data, $includeData)
{
Expand Down
9 changes: 7 additions & 2 deletions src/Nelmio/Alice/Fixtures/Parser/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@
class Parser
{
/**
* @var array
**/
* @var MethodInterface[]
*/
private $parsers = [];

/**
* Parser constructor.
*
* @param MethodInterface[] $parsers
*/
public function __construct(array $parsers)
{
foreach ($parsers as $parser) {
Expand Down
3 changes: 2 additions & 1 deletion src/Nelmio/Alice/Instances/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function find($name, $property = null)

/**
* Get instance keys that match given mask
* @param string $mask
* @param string $mask
* @return string[]
*/
protected function getKeysByMask($mask)
Expand All @@ -150,6 +150,7 @@ protected function getKeysByMask($mask)
)
);
}

return $this->keysByMask[$mask];
}

Expand Down
5 changes: 4 additions & 1 deletion src/Nelmio/Alice/Instances/Instantiator/Instantiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
class Instantiator
{
/**
* @var array
* @var MethodInterface[]
**/
protected $methods;

/**
* @param MethodInterface[] $methods
*/
public function __construct(array $methods)
{
foreach ($methods as $method) {
Expand Down
Loading

0 comments on commit ff55f28

Please sign in to comment.