| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * apparat-dev | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @category    Apparat | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @package     Apparat\Dev | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @subpackage  Apparat\Dev\Infrastructure | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @author      Joschi Kuphal <[email protected]> / @jkphl | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @copyright   Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @license     http://opensource.org/licenses/MIT The MIT License (MIT) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | /*********************************************************************************** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  *  The MIT License (MIT) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  *  Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  *  Permission is hereby granted, free of charge, to any person obtaining a copy of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  *  this software and associated documentation files (the "Software"), to deal in | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  *  the Software without restriction, including without limitation the rights to | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  *  the Software, and to permit persons to whom the Software is furnished to do so, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  *  subject to the following conditions: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  *  The above copyright notice and this permission notice shall be included in all | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  *  copies or substantial portions of the Software. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  ***********************************************************************************/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | namespace Apparat\Dev\Infrastructure\Factory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | use Apparat\Dev\Infrastructure\Mutator\ArticleObjectMutator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | use Apparat\Dev\Infrastructure\Mutator\ContactObjectMutator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | use Apparat\Dev\Infrastructure\Mutator\ObjectMutatorInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | use Apparat\Dev\Ports\Repository; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | use Apparat\Kernel\Ports\Kernel; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | use Apparat\Object\Domain\Model\Object\ObjectInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | use Apparat\Object\Ports\Types\Object; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  * Object factory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  * @package Apparat\Dev | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  * @subpackage Apparat\Dev\Infrastructure | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | class ObjectFactory extends AbstractObjectFactory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * Create a repository object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * @param \DateTimeInterface $creationDate Creation date | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * @param int $objectId Object ID | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * @param array $config Object configuration | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 2 |  |     public function create(\DateTimeInterface $creationDate, $objectId, array $config) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 | 2 |  |         $objectTypeMethod = ucfirst($config[Repository::TYPE]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 2 |  |         $objectMutator = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         /** @var ObjectInterface $object */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 | 2 |  |         $object = $this->{'create'.$objectTypeMethod}($creationDate, $objectMutator); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         // Create the object revisions | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 2 |  |         $this->createObjectRevisions($object, $config, $objectMutator); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         // Eventually hide the object if necessary | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 2 |  |         if (($config[Repository::HIDDEN] > 0) ? (rand(0, 100) < ($config[Repository::HIDDEN] * 100)) : false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 | 2 |  |             $object->delete()->persist(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 2 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 2 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      * Create the object revisions | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      * @param ObjectInterface $object Object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      * @param array $config Object configuration | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * @param ObjectMutatorInterface $objectMutator Object mutator | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 85 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 86 | 2 |  |     protected function createObjectRevisions( | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |         ObjectInterface $object, | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  |         array $config, | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |         ObjectMutatorInterface $objectMutator | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  |     ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  |         // Determine the amount of archive revisions to create | 
            
                                                                        
                            
            
                                    
            
            
                | 92 | 2 |  |         $revisions = ($config[Repository::REVISIONS] < 0) ? | 
            
                                                                        
                            
            
                                    
            
            
                | 93 | 2 |  |             rand(1, abs($config[Repository::REVISIONS]) + 1) : (1 + $config[Repository::REVISIONS]); | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |         // Determine the draft status | 
            
                                                                        
                            
            
                                    
            
            
                | 96 | 2 |  |         $draft = (($config[Repository::DRAFTS] > 0) ? (rand(0, 100) < $config[Repository::DRAFTS] * 100) : 0); | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  |         // Build the revision path list | 
            
                                                                        
                            
            
                                    
            
            
                | 99 | 2 |  |         for ($revision = 1; $revision < $revisions - $draft; ++$revision) { | 
            
                                                                        
                            
            
                                    
            
            
                | 100 | 2 |  |             $objectMutator->mutate($object)->publish()->persist(); | 
            
                                                                        
                            
            
                                    
            
            
                | 101 | 2 |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 102 | 2 |  |         if ($revision <= $revisions - $draft) { | 
            
                                                                        
                            
            
                                    
            
            
                | 103 | 2 |  |             $objectMutator->mutate($object)->publish()->persist(); | 
            
                                                                        
                            
            
                                    
            
            
                | 104 | 2 |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 105 | 2 |  |         if ($draft) { | 
            
                                                                        
                            
            
                                    
            
            
                | 106 | 2 |  |             $objectMutator->mutate($object)->persist(); | 
            
                                                                        
                            
            
                                    
            
            
                | 107 | 2 |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 108 | 2 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      * Create an article object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |      * @param \DateTimeInterface $creationDate Creation date | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |      * @return ObjectInterface Article | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 | 1 |  |     protected function createArticle(\DateTimeInterface $creationDate, ObjectMutatorInterface &$objectMutator = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |         /** @var ObjectMutatorInterface $objectMutator */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 | 1 |  |         $objectMutator = Kernel::create(ArticleObjectMutator::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 | 1 |  |         return $objectMutator->initialize($this->repository->createObject(Object::ARTICLE, '', [], $creationDate)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |      * Create a contact object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |      * @param \DateTimeInterface $creationDate Creation date | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |      * @return ObjectInterface Contact | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 | 1 |  |     protected function createContact(\DateTimeInterface $creationDate, ObjectMutatorInterface &$objectMutator = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |         /** @var ObjectMutatorInterface $objectMutator */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 | 1 |  |         $objectMutator = Kernel::create(ContactObjectMutator::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 | 1 |  |         return $objectMutator->initialize($this->repository->createObject(Object::CONTACT, '', [], $creationDate)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 135 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 136 |  |  |  | 
            
                        
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: