From 01d14af2a6f192bb45ade85b8a90d256d909e1c2 Mon Sep 17 00:00:00 2001 From: Michael Wilson Date: Mon, 27 Jun 2016 10:25:47 -0500 Subject: [PATCH 01/10] add `has('$dep.whatever')` to ioc manager --- CHANGELOG.md | 1 + ioc.md | 3 +++ src/Traits/ManagesItemsTrait.php | 5 +++++ tests/Scenarios/ManagesIocScenario.php | 8 ++++++++ 4 files changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 894e09c..b584bde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ All Notable changes to `Manager` will be documented in this file - Move to a new testing structure - Add integration tests - Cleanup and refactor + - add `has('$dep.whatever')` interpolation # v0.8.9 - 3-11-2016 - Add full composer.json diff --git a/ioc.md b/ioc.md index 4b7e6d1..962b8a1 100644 --- a/ioc.md +++ b/ioc.md @@ -125,4 +125,7 @@ If you pass a value that is not a registered dependency, then the value itself i NOTE: For the moment, you cannot prepare dependencies that are instances of containers. + +### Has() +If you want to check if a dependency exists, use `$manager->has('$dep.whatever')`. Not the single quotes. Any feedback here would be appreciated. Take a look at `IocManagerInterface` for future plans. diff --git a/src/Traits/ManagesItemsTrait.php b/src/Traits/ManagesItemsTrait.php index 367126d..bd2255a 100644 --- a/src/Traits/ManagesItemsTrait.php +++ b/src/Traits/ManagesItemsTrait.php @@ -258,6 +258,11 @@ public function all() */ public function exists($alias) { + // If we are looking for a dependency + if (strpos($alias, '$dep.') !== false) { + $alias = str_replace('$dep', $this->getDiItemsName(), $alias); + } + $repo = $this->getItemsName(); $loc = &$this->$repo; foreach (explode('.', $alias) as $step) { diff --git a/tests/Scenarios/ManagesIocScenario.php b/tests/Scenarios/ManagesIocScenario.php index 2af6760..7d6558f 100644 --- a/tests/Scenarios/ManagesIocScenario.php +++ b/tests/Scenarios/ManagesIocScenario.php @@ -315,6 +315,14 @@ public function test_throws_exception_for_no_item_set() $manager->fetch('nothing_set'); } + public function test_has_with_dep() + { + $manager = $this->getManager(); + $manager->di('dependency', 'A\\Test\\Class'); + + $this->assertTrue($manager->has('$dep.dependency'), "Failed to interpolate `dep` "); + } + public function test_complex_example() { $this->setupTestData(); From 63f4a1de960f685b6a039f23e4ff52ad79bf816a Mon Sep 17 00:00:00 2001 From: Michael Wilson Date: Mon, 27 Jun 2016 11:55:01 -0500 Subject: [PATCH 02/10] minor typo --- src/Manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Manager.php b/src/Manager.php index a3db971..90078ae 100644 --- a/src/Manager.php +++ b/src/Manager.php @@ -35,7 +35,7 @@ class Manager implements * The items stored in the manager * @var array $items Items governed by manager */ - protected $items; + protected $_items; /** * Build a new manager instance From 8b7bdb7fb34b7467d73d0a674e16e61d22eea15c Mon Sep 17 00:00:00 2001 From: Michael Wilson Date: Mon, 27 Jun 2016 11:56:29 -0500 Subject: [PATCH 03/10] remove $items from manager classes --- src/BasicManager.php | 6 ------ src/ConfigManager.php | 6 ------ src/Manager.php | 6 ------ src/UberManager.php | 6 ------ 4 files changed, 24 deletions(-) diff --git a/src/BasicManager.php b/src/BasicManager.php index 9f549d2..a416052 100644 --- a/src/BasicManager.php +++ b/src/BasicManager.php @@ -19,12 +19,6 @@ class BasicManager implements { use ManagesItemsTrait; - /** - * The items stored in the manager - * @var array $items Items governed by manager - */ - protected $items; - /** * Build a new manager instance * @param array $items diff --git a/src/ConfigManager.php b/src/ConfigManager.php index 4f3dd1b..58c667a 100644 --- a/src/ConfigManager.php +++ b/src/ConfigManager.php @@ -31,12 +31,6 @@ class ConfigManager implements { use ManagesItemsTrait, ArrayableTrait, LoadsFilesTrait; - /** - * The items stored in the manager - * @var array $items Items governed by manager - */ - protected $items; - /** * Build a new manager instance * @param array $items diff --git a/src/Manager.php b/src/Manager.php index 90078ae..ab782d7 100644 --- a/src/Manager.php +++ b/src/Manager.php @@ -31,12 +31,6 @@ class Manager implements { use ManagesItemsTrait, ChainsNestedItemsTrait, ArrayableTrait; - /** - * The items stored in the manager - * @var array $items Items governed by manager - */ - protected $_items; - /** * Build a new manager instance * @param array $items diff --git a/src/UberManager.php b/src/UberManager.php index c9c46da..2c8f5d3 100644 --- a/src/UberManager.php +++ b/src/UberManager.php @@ -42,12 +42,6 @@ class UberManager implements { use ManagesItemsTrait, ChainsNestedItemsTrait, ArrayableTrait, ManagesIocTrait, LoadsFilesTrait; - /** - * The items stored in the manager - * @var array $items Items governed by manager - */ - protected $items; - /** * Build a new manager instance * @param array $items From afe49706c3420eca27f7543e90d475adf7a63d22 Mon Sep 17 00:00:00 2001 From: Michael Wilson Date: Mon, 27 Jun 2016 12:21:18 -0500 Subject: [PATCH 04/10] add linking (multiple aliases) to ioc manager --- CHANGELOG.md | 1 + ioc.md | 8 ++++++++ src/Traits/ManagesIocTrait.php | 23 ++++++++++++++++++++++- tests/Scenarios/ManagesIocScenario.php | 10 ++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b584bde..4de0fa2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All Notable changes to `Manager` will be documented in this file - Add integration tests - Cleanup and refactor - add `has('$dep.whatever')` interpolation + - add linking (multiple aliases) to ioc manager # v0.8.9 - 3-11-2016 - Add full composer.json diff --git a/ioc.md b/ioc.md index 962b8a1..be8c241 100644 --- a/ioc.md +++ b/ioc.md @@ -55,6 +55,14 @@ When you're ready to call dependencies: $manager->fetch('event_dispatcher'); ``` +You may also register multiple aliases to a single dependency +```php +$manager->di(['one', 'two', 'three'], $factory); +$manager->fetch('one'); +$manager->fetch('two'); +$manager->fetch('three'); // All the same +``` + ## Dependencies that need Dependencies The easiest way to setup a dependency that needs a dependency is to use a closure. ```php diff --git a/src/Traits/ManagesIocTrait.php b/src/Traits/ManagesIocTrait.php index 082362e..9830063 100644 --- a/src/Traits/ManagesIocTrait.php +++ b/src/Traits/ManagesIocTrait.php @@ -56,6 +56,13 @@ public function getIocManifest() */ public function fetch($alias, $fallback = '_michaels_no_fallback') { + // If this is a link, just go back to the master + $link = $this->getIfExists($this->nameOfIocManifest . ".$alias"); + if (is_string($link) && strpos($link, '_michaels_link_') !== false) { + return $this->fetch(str_replace('_michaels_link_', '', $link)); + } + + // Otherwise, continue $shared = $this->getIfExists($this->nameOfIocManifest . "._singletons.$alias"); if ($shared instanceof NoItemFoundMessage) { @@ -66,7 +73,7 @@ public function fetch($alias, $fallback = '_michaels_no_fallback') if (is_object($shared)) { return $shared; - // This is shared, but we must produce and cache it + // This is shared, but we must produce and cache it } else { $object = $this->produceDependency($alias, $fallback); $this->set($this->nameOfIocManifest . "._singletons.$alias", $object); @@ -90,6 +97,13 @@ public function fetch($alias, $fallback = '_michaels_no_fallback') */ public function di($alias, $factory, array $declared = null) { + // Setup links, if necessary + if (is_array($alias)) { + $links = $alias; + $alias = $alias[0]; + unset($links[0]); + } + $this->set($this->nameOfIocManifest . ".$alias", $factory); // Setup any declared dependencies @@ -97,6 +111,13 @@ public function di($alias, $factory, array $declared = null) $this->set($this->nameOfIocManifest . "._declarations.$alias", $declared); } + // Add Links + if (!empty($links)) { + foreach ($links as $link) { + $this->set($this->nameOfIocManifest . ".$link", "_michaels_link_$alias"); + } + } + return $this; } diff --git a/tests/Scenarios/ManagesIocScenario.php b/tests/Scenarios/ManagesIocScenario.php index 7d6558f..bbbc0ad 100644 --- a/tests/Scenarios/ManagesIocScenario.php +++ b/tests/Scenarios/ManagesIocScenario.php @@ -323,6 +323,16 @@ public function test_has_with_dep() $this->assertTrue($manager->has('$dep.dependency'), "Failed to interpolate `dep` "); } + public function test_links() + { + $manager = $this->getManager(); + $manager->di(['one', 'two', 'three'], '\\stdClass'); + + $this->assertInstanceOf('\stdClass', $manager->fetch('one'), "failed to produce the master'"); + $this->assertInstanceOf('\stdClass', $manager->fetch('two'), "failed to produce the first link'"); + $this->assertInstanceOf('\stdClass', $manager->fetch('three'), "failed to produce the second link'"); + } + public function test_complex_example() { $this->setupTestData(); From 34da2be1563465c2323d44618f8d2c9f80146210 Mon Sep 17 00:00:00 2001 From: Michael Wilson Date: Mon, 27 Jun 2016 15:47:13 -0500 Subject: [PATCH 05/10] update return for ioc --- src/Contracts/IocContainerInterface.php | 2 +- src/Traits/ManagesIocTrait.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Contracts/IocContainerInterface.php b/src/Contracts/IocContainerInterface.php index 6d1d02b..670ce1a 100644 --- a/src/Contracts/IocContainerInterface.php +++ b/src/Contracts/IocContainerInterface.php @@ -13,7 +13,7 @@ interface IocContainerInterface * Returns the request object with all dependencies * * @param string $alias - * @return object + * @return mixed */ public function fetch($alias); } diff --git a/src/Traits/ManagesIocTrait.php b/src/Traits/ManagesIocTrait.php index 9830063..8e6f09b 100644 --- a/src/Traits/ManagesIocTrait.php +++ b/src/Traits/ManagesIocTrait.php @@ -51,7 +51,7 @@ public function getIocManifest() * * @param string $alias * @param string|mixed $fallback - * @return object + * @return mixed * @throws \Exception */ public function fetch($alias, $fallback = '_michaels_no_fallback') From b32b1e4445c60b394a01e9696b4317ab425dedb4 Mon Sep 17 00:00:00 2001 From: Michael Wilson Date: Mon, 27 Jun 2016 17:48:36 -0500 Subject: [PATCH 06/10] fetch unregistered deps by class name --- CHANGELOG.md | 1 + ioc.md | 5 +++++ src/Traits/ManagesIocTrait.php | 2 ++ tests/Scenarios/ManagesIocScenario.php | 6 ++++++ 4 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4de0fa2..f2c4940 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All Notable changes to `Manager` will be documented in this file - Cleanup and refactor - add `has('$dep.whatever')` interpolation - add linking (multiple aliases) to ioc manager + - add to ioc manager, fetch a class by string # v0.8.9 - 3-11-2016 - Add full composer.json diff --git a/ioc.md b/ioc.md index be8c241..31e801b 100644 --- a/ioc.md +++ b/ioc.md @@ -63,6 +63,11 @@ $manager->fetch('two'); $manager->fetch('three'); // All the same ``` +And, just ask for a class. If it exists (and nothing by that name was registered), it will be loaded. +```php +$manager->fetch('Some/Class') +``` + ## Dependencies that need Dependencies The easiest way to setup a dependency that needs a dependency is to use a closure. ```php diff --git a/src/Traits/ManagesIocTrait.php b/src/Traits/ManagesIocTrait.php index 8e6f09b..18a57df 100644 --- a/src/Traits/ManagesIocTrait.php +++ b/src/Traits/ManagesIocTrait.php @@ -181,6 +181,8 @@ protected function produceDependency($alias, $fallback = '_michaels_no_fallback' if ($factory instanceof NoItemFoundMessage) { if ($fallback !== '_michaels_no_fallback') { return $fallback; + } elseif (class_exists($alias)) { + return new $alias; } else { throw new ItemNotFoundException("$alias not found"); } diff --git a/tests/Scenarios/ManagesIocScenario.php b/tests/Scenarios/ManagesIocScenario.php index bbbc0ad..b1852e9 100644 --- a/tests/Scenarios/ManagesIocScenario.php +++ b/tests/Scenarios/ManagesIocScenario.php @@ -333,6 +333,12 @@ public function test_links() $this->assertInstanceOf('\stdClass', $manager->fetch('three'), "failed to produce the second link'"); } + public function test_get_class() + { + $manager = $this->getManager(); + $this->assertInstanceOf('Michaels\Manager\Manager', $manager->fetch('\Michaels\Manager\Manager'), "failed to produce a dependency from a class'"); + } + public function test_complex_example() { $this->setupTestData(); From 2f22eeb9ed82f92a62bc35d2c82d45bc57d982f8 Mon Sep 17 00:00:00 2001 From: Michael Wilson Date: Mon, 27 Jun 2016 18:08:01 -0500 Subject: [PATCH 07/10] allow user to disable namespacing in file loading --- CHANGELOG.md | 1 + src/FileLoader.php | 15 ++++++++++----- src/Traits/LoadsFilesTrait.php | 8 ++++---- tests/Unit/FileLoaderTest.php | 14 ++++++++++++++ 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2c4940..726b989 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All Notable changes to `Manager` will be documented in this file - add `has('$dep.whatever')` interpolation - add linking (multiple aliases) to ioc manager - add to ioc manager, fetch a class by string + - Allow user to force no namespacing in file loading # v0.8.9 - 3-11-2016 - Add full composer.json diff --git a/src/FileLoader.php b/src/FileLoader.php index fa28d9a..a7954ed 100644 --- a/src/FileLoader.php +++ b/src/FileLoader.php @@ -74,7 +74,7 @@ public function addDecoder(DecoderInterface $decoder) */ public function addFiles($files) { - if ($files instanceof Filebag) { + if ($files instanceof FileBag) { $this->fileBag = $files; return; } @@ -92,9 +92,9 @@ public function addFiles($files) * @return array * @throws Exception */ - public function process() + public function process($ns = true) { - return $this->decodedData = $this->decodeFileBagData($this->fileBag); + return $this->decodedData = $this->decodeFileBagData($this->fileBag, $ns); } /** @@ -102,10 +102,11 @@ public function process() * A file bag is an array of SplFileInfo objects. * * @param array|FileBag $fileBag + * @param bool $ns * @return array * @throws Exception */ - public function decodeFileBagData(FileBag $fileBag) + public function decodeFileBagData(FileBag $fileBag, $ns = true) { $decodedData = []; $files = $fileBag->getAllFileInfoObjects(); @@ -120,7 +121,11 @@ public function decodeFileBagData(FileBag $fileBag) $fileData = $this->decodeFile($file); if ($fileData) { foreach ($fileData as $k => $v) { - $decodedData[$namespace][$k] = $v; + if ($ns === true) { + $decodedData[$namespace][$k] = $v; + } else { + $decodedData[$k] = $v; + } } } } diff --git a/src/Traits/LoadsFilesTrait.php b/src/Traits/LoadsFilesTrait.php index e37ca08..a225581 100644 --- a/src/Traits/LoadsFilesTrait.php +++ b/src/Traits/LoadsFilesTrait.php @@ -40,17 +40,17 @@ protected function initializeFileLoader(FileLoader $fileLoader = null) * @param $append boolean true, if data should be appended to the manager. * @return array */ - public function loadFiles(array $files, $append = false) + public function loadFiles(array $files, $append = false, $namespace = true) { $this->initializeFileLoader(); $this->fileLoader->addFiles($files); - $data = $this->fileLoader->process(); + $data = $this->fileLoader->process($namespace); $this->hydrate($data, $append); } - public function loadFile($file, $append = false) + public function loadFile($file, $append = false, $namespace = true) { - return $this->loadFiles([$file], $append); + return $this->loadFiles([$file], $append, $namespace = true); } /** diff --git a/tests/Unit/FileLoaderTest.php b/tests/Unit/FileLoaderTest.php index 7fb1050..1ce838f 100644 --- a/tests/Unit/FileLoaderTest.php +++ b/tests/Unit/FileLoaderTest.php @@ -164,6 +164,20 @@ public function test_using_explicit_namespaces() $this->assertEquals($expected, $actual, "failed to custom namespace the second file"); } + public function test_using_no_namespaces() + { + $fileLoader = new FileLoader(); + $fileLoader->addFiles([ + new \SplFileInfo($GLOBALS['test_config']['test_dir'] . '/Fixtures/FilesWithGoodData/jsonConfig.json') + ]); + + $expected = $this->testData; + + $actual = $fileLoader->process(false); + + $this->assertEquals($expected, $actual, "failed to disaple namespacing"); + } + public function test_loading_files_as_a_path() { $fileLoader = new FileLoader(); From 240526cc51226007c51994f645830e27fdc517e4 Mon Sep 17 00:00:00 2001 From: Michael Wilson Date: Mon, 27 Jun 2016 18:48:28 -0500 Subject: [PATCH 08/10] typo --- src/Traits/LoadsFilesTrait.php | 3 ++- tests/Unit/FileLoaderTest.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Traits/LoadsFilesTrait.php b/src/Traits/LoadsFilesTrait.php index a225581..d9984a9 100644 --- a/src/Traits/LoadsFilesTrait.php +++ b/src/Traits/LoadsFilesTrait.php @@ -38,6 +38,7 @@ protected function initializeFileLoader(FileLoader $fileLoader = null) * * @param array $files an array of SplFileInfo Objects * @param $append boolean true, if data should be appended to the manager. + * @param bool $namespace * @return array */ public function loadFiles(array $files, $append = false, $namespace = true) @@ -50,7 +51,7 @@ public function loadFiles(array $files, $append = false, $namespace = true) public function loadFile($file, $append = false, $namespace = true) { - return $this->loadFiles([$file], $append, $namespace = true); + return $this->loadFiles([$file], $append, $namespace); } /** diff --git a/tests/Unit/FileLoaderTest.php b/tests/Unit/FileLoaderTest.php index 1ce838f..9e02bbe 100644 --- a/tests/Unit/FileLoaderTest.php +++ b/tests/Unit/FileLoaderTest.php @@ -175,7 +175,7 @@ public function test_using_no_namespaces() $actual = $fileLoader->process(false); - $this->assertEquals($expected, $actual, "failed to disaple namespacing"); + $this->assertEquals($expected, $actual, "failed to disable namespacing"); } public function test_loading_files_as_a_path() From 1002f37395dd746ecabd18616f6156f458e2c45c Mon Sep 17 00:00:00 2001 From: Michael Wilson Date: Mon, 22 Aug 2016 10:42:29 -0500 Subject: [PATCH 09/10] cleanup and tests to 100% --- src/FileLoader.php | 2 +- .../Integration/Managers/BasicManagerTest.php | 20 +++++++++++++++++++ tests/Scenarios/LoadsFilesScenario.php | 13 ++++++++++++ tests/Unit/Bags/FileBagTest.php | 1 + tests/Unit/Decoders/JsonDecoderTest.php | 2 ++ tests/Unit/Decoders/PhpDecoderTest.php | 2 ++ tests/Unit/Decoders/YamlDecoderTest.php | 2 ++ 7 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tests/Integration/Managers/BasicManagerTest.php diff --git a/src/FileLoader.php b/src/FileLoader.php index a7954ed..d288f94 100644 --- a/src/FileLoader.php +++ b/src/FileLoader.php @@ -89,8 +89,8 @@ public function addFiles($files) /** * Process the current FileBag and return an array + * @param bool $ns * @return array - * @throws Exception */ public function process($ns = true) { diff --git a/tests/Integration/Managers/BasicManagerTest.php b/tests/Integration/Managers/BasicManagerTest.php new file mode 100644 index 0000000..f6b10fb --- /dev/null +++ b/tests/Integration/Managers/BasicManagerTest.php @@ -0,0 +1,20 @@ +assertEquals($this->defaultArray, $manager->all()); } + public function test_load_single_file() + { + $this->setupDefaultArray(); + $manager = $this->getManager(); + $manager->loadFile(new \SplFileInfo(realpath(__DIR__ . '/../Fixtures/FilesWithGoodData/jsonConfig.json'))); + + $expected = $this->defaultArray; + unset($expected['phpConfig']); + unset($expected['yamlConfig']); + + $this->assertEquals($expected, $manager->all()); + } + public function test_with_decoder() { $goodCustomTestFileDirectory = realpath(__DIR__ . '/../Fixtures/CustomFileWithGoodData'); diff --git a/tests/Unit/Bags/FileBagTest.php b/tests/Unit/Bags/FileBagTest.php index ecd6d35..03d63b3 100644 --- a/tests/Unit/Bags/FileBagTest.php +++ b/tests/Unit/Bags/FileBagTest.php @@ -25,6 +25,7 @@ class FileBagTest extends \PHPUnit_Framework_TestCase private $badTestFileObjects = []; + /** @var FileBag */ private $fileBag; /** diff --git a/tests/Unit/Decoders/JsonDecoderTest.php b/tests/Unit/Decoders/JsonDecoderTest.php index 3bae67d..758db70 100644 --- a/tests/Unit/Decoders/JsonDecoderTest.php +++ b/tests/Unit/Decoders/JsonDecoderTest.php @@ -7,6 +7,8 @@ class JsonDecoderTest extends \PHPUnit_Framework_TestCase { private $jsonData; private $testArrayData; + + /** @var JsonDecoder */ private $jsonDecoder; public function setup() diff --git a/tests/Unit/Decoders/PhpDecoderTest.php b/tests/Unit/Decoders/PhpDecoderTest.php index 8260c15..318f7d3 100644 --- a/tests/Unit/Decoders/PhpDecoderTest.php +++ b/tests/Unit/Decoders/PhpDecoderTest.php @@ -7,6 +7,8 @@ class PhpDecoderTest extends \PHPUnit_Framework_TestCase { private $phpData; private $testArrayData; + + /** @var PhpDecoder */ private $phpDecoder; public function setup() diff --git a/tests/Unit/Decoders/YamlDecoderTest.php b/tests/Unit/Decoders/YamlDecoderTest.php index e09b351..a80d188 100644 --- a/tests/Unit/Decoders/YamlDecoderTest.php +++ b/tests/Unit/Decoders/YamlDecoderTest.php @@ -8,6 +8,8 @@ class YamlDecoderTest extends \PHPUnit_Framework_TestCase { private $yamlData; private $testArrayData; + + /** @var YamlDecoder */ private $yamlDecoder; public function setup() From 19a64397fbf30e94eddeb62d88efe507feaac9c4 Mon Sep 17 00:00:00 2001 From: Michael Wilson Date: Mon, 22 Aug 2016 11:03:58 -0500 Subject: [PATCH 10/10] cleanup scrutinizer --- src/Bags/FileBag.php | 2 +- src/Contracts/IocManagerInterface.php | 1 + src/Contracts/ManagesItemsInterface.php | 4 ++-- src/Decoders/JsonDecoder.php | 2 +- src/Decoders/YamlDecoder.php | 2 +- src/FileLoader.php | 2 +- src/Traits/ArrayableTrait.php | 2 +- src/Traits/CollectionTrait.php | 5 +++-- src/Traits/DependsOnManagesItemsTrait.php | 4 ++-- src/Traits/LoadsFilesTrait.php | 4 ++-- src/Traits/ManagesIocTrait.php | 2 +- src/Traits/ManagesItemsTrait.php | 6 +++--- src/UberManager.php | 1 - 13 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/Bags/FileBag.php b/src/Bags/FileBag.php index f90fc0f..a294c99 100644 --- a/src/Bags/FileBag.php +++ b/src/Bags/FileBag.php @@ -61,7 +61,7 @@ protected function initialize(array $splFileInfoObjects = []) /** * Check for an \SplFileInfo object or a custom namespaces object * @param $entity - * @return bool + * @return \SplFileInfo|\SplFileInfo[]|string */ protected function createSplFileInfoObject($entity) { diff --git a/src/Contracts/IocManagerInterface.php b/src/Contracts/IocManagerInterface.php index 1adc153..e3df938 100644 --- a/src/Contracts/IocManagerInterface.php +++ b/src/Contracts/IocManagerInterface.php @@ -40,6 +40,7 @@ public function share($alias); * Add a pipeline to to the que for a specific item * @param $alias * @param $pipeline + * @return void */ public function setup($alias, $pipeline); diff --git a/src/Contracts/ManagesItemsInterface.php b/src/Contracts/ManagesItemsInterface.php index 72a3bf1..e222509 100644 --- a/src/Contracts/ManagesItemsInterface.php +++ b/src/Contracts/ManagesItemsInterface.php @@ -53,11 +53,11 @@ public function set($alias, $item = null); * Push a value or values onto the end of an array inside manager * @param string $alias The level of nested data * @param mixed $value The first value to append - * @param null|mixed $_ Optional other values to apend + * @param null|mixed $other Optional other values to amend * @return int Number of items pushed * @throws ItemNotFoundException If pushing to unset array */ - public function push($alias, $value, $_ = null); + public function push($alias, $value, $other = null); /** * Get a single item diff --git a/src/Decoders/JsonDecoder.php b/src/Decoders/JsonDecoder.php index 465bb60..2d71d67 100644 --- a/src/Decoders/JsonDecoder.php +++ b/src/Decoders/JsonDecoder.php @@ -36,7 +36,7 @@ public function decode($data) /** * Returns MimeType - * @return string + * @return string[] */ public function getMimeType() { diff --git a/src/Decoders/YamlDecoder.php b/src/Decoders/YamlDecoder.php index 01e8ac6..8c414d2 100644 --- a/src/Decoders/YamlDecoder.php +++ b/src/Decoders/YamlDecoder.php @@ -22,7 +22,7 @@ class YamlDecoder implements DecoderInterface public function decode($data) { $parser = new Parser(); - $this->arrayData = $parser->parse($data); + $this->arrayData = (array) $parser->parse($data); return $this->arrayData; } diff --git a/src/FileLoader.php b/src/FileLoader.php index d288f94..39eb603 100644 --- a/src/FileLoader.php +++ b/src/FileLoader.php @@ -194,7 +194,7 @@ protected function checkAndAddDefaultDecoder($mimeType) /** * Decodes a single file using registered decoders * @param \SplFileInfo $file - * @return null + * @return string */ protected function decodeFile($file) { diff --git a/src/Traits/ArrayableTrait.php b/src/Traits/ArrayableTrait.php index 1b29274..139a415 100644 --- a/src/Traits/ArrayableTrait.php +++ b/src/Traits/ArrayableTrait.php @@ -68,7 +68,7 @@ public function count() /** * @implements JSONSerializable - * @return string + * @return array */ public function jsonSerialize() { diff --git a/src/Traits/CollectionTrait.php b/src/Traits/CollectionTrait.php index 7d811bf..3985d70 100644 --- a/src/Traits/CollectionTrait.php +++ b/src/Traits/CollectionTrait.php @@ -10,6 +10,7 @@ * MUST be used with ManagesItemsTrait * * @implements Michaels\Manager\Contracts\ChainsNestedItemsInterface + * @method addToChain() from ChainsNestedItems * @package Michaels\Manager */ trait CollectionTrait @@ -30,7 +31,7 @@ trait CollectionTrait /** * Converts an array to a collection if value is arrayable and config is set * @param $value - * @return static + * @return ArrayImitator */ public function toCollection($value) { @@ -161,8 +162,8 @@ protected function callCollectionMethod($method, $arguments, $instance, $flag, $ $return = $this; break; - default: case (static::$RETURN_ARRAY): + default: $return = $value->toArray(); } diff --git a/src/Traits/DependsOnManagesItemsTrait.php b/src/Traits/DependsOnManagesItemsTrait.php index 8343d7d..8f9d8b3 100644 --- a/src/Traits/DependsOnManagesItemsTrait.php +++ b/src/Traits/DependsOnManagesItemsTrait.php @@ -48,11 +48,11 @@ abstract public function set($alias, $item = null); * Push a value or values onto the end of an array inside manager * @param string $alias The level of nested data * @param mixed $value The first value to append - * @param null|mixed $_ Optional other values to apend + * @param null|mixed $other Optional other values to apend * @return int Number of items pushed * @throws ItemNotFoundException If pushing to unset array */ - abstract public function push($alias, $value, $_ = null); + abstract public function push($alias, $value, $other = null); /** * Get a single item diff --git a/src/Traits/LoadsFilesTrait.php b/src/Traits/LoadsFilesTrait.php index d9984a9..13af961 100644 --- a/src/Traits/LoadsFilesTrait.php +++ b/src/Traits/LoadsFilesTrait.php @@ -39,7 +39,7 @@ protected function initializeFileLoader(FileLoader $fileLoader = null) * @param array $files an array of SplFileInfo Objects * @param $append boolean true, if data should be appended to the manager. * @param bool $namespace - * @return array + * @return void */ public function loadFiles(array $files, $append = false, $namespace = true) { @@ -51,7 +51,7 @@ public function loadFiles(array $files, $append = false, $namespace = true) public function loadFile($file, $append = false, $namespace = true) { - return $this->loadFiles([$file], $append, $namespace); + $this->loadFiles([$file], $append, $namespace); } /** diff --git a/src/Traits/ManagesIocTrait.php b/src/Traits/ManagesIocTrait.php index 18a57df..a0da092 100644 --- a/src/Traits/ManagesIocTrait.php +++ b/src/Traits/ManagesIocTrait.php @@ -33,7 +33,7 @@ public function initDi(array $components = []) /** * Returns the entire IoC Manifest - * @return array + * @return array|NoItemFoundMessage */ public function getIocManifest() { diff --git a/src/Traits/ManagesItemsTrait.php b/src/Traits/ManagesItemsTrait.php index bd2255a..9fb008d 100644 --- a/src/Traits/ManagesItemsTrait.php +++ b/src/Traits/ManagesItemsTrait.php @@ -147,13 +147,13 @@ public function set($alias, $item = null) * Push a value or values onto the end of an array inside manager * @param string $alias The level of nested data * @param mixed $value The first value to append - * @param null|mixed $_ Optional other values to apend + * @param null|mixed $other Optional other values to apend * @return int Number of items pushed * @throws ItemNotFoundException If pushing to unset array */ - public function push($alias, $value, $_ = null) + public function push($alias, $value, $other = null) { - if (isset($_)) { + if (isset($other)) { $values = func_get_args(); array_shift($values); } else { diff --git a/src/UberManager.php b/src/UberManager.php index 2c8f5d3..351ccd7 100644 --- a/src/UberManager.php +++ b/src/UberManager.php @@ -38,7 +38,6 @@ class UberManager implements // Standards ContainerInterface - { use ManagesItemsTrait, ChainsNestedItemsTrait, ArrayableTrait, ManagesIocTrait, LoadsFilesTrait;