| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace spec\Yproximite\Api\Service; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use PhpSpec\ObjectBehavior; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Yproximite\Api\Client\Client; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Yproximite\Api\Model\Site\Site; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Yproximite\Api\Service\SiteService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Yproximite\Api\Factory\ModelFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Yproximite\Api\Message\Site\SitePostMessage; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Yproximite\Api\Message\Site\SitePatchMessage; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Yproximite\Api\Message\Site\PlatformChildrenListMessage; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | class SiteServiceSpec extends ObjectBehavior | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 16 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |     function it_is_initializable() | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |         $this->shouldHaveType(SiteService::class); | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     function let(Client $client, ModelFactory $factory) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         $this->beConstructedWith($client, $factory); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 27 |  | View Code Duplication |     function it_should_get_sites(Client $client, ModelFactory $factory) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         $method = 'GET'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $path   = 'sites'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $client->sendRequest($method, $path)->willReturn([]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $client->sendRequest($method, $path)->shouldBeCalled(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $factory->createMany(Site::class, [])->willReturn([]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $this->getSites(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 40 |  | View Code Duplication |     function it_should_get_site(Client $client, ModelFactory $factory, Site $site) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $method = 'GET'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $path   = 'sites/1'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $client->sendRequest($method, $path)->willReturn([]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $client->sendRequest($method, $path)->shouldBeCalled(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $factory->create(Site::class, [])->willReturn($site); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $this->getSite(1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     function it_should_post_site( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         Client $client, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         ModelFactory $factory, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         SitePostMessage $message, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         Site $site | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $message->getCompanyId()->willReturn(1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $message->build()->willReturn([]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $method = 'POST'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $path   = 'sites'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $data   = ['api_site' => []]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $client->sendRequest($method, $path, $data)->willReturn([]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $client->sendRequest($method, $path, $data)->shouldBeCalled(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $factory->create(Site::class, [])->willReturn($site); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $this->postSite($message); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     function it_should_patch_site( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         Client $client, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         ModelFactory $factory, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         SitePatchMessage $message, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         Site $site | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         $message->getId()->willReturn(1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $message->build()->willReturn([]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $method = 'PATCH'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         $path   = 'sites/1'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         $data   = ['api_site' => []]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         $client->sendRequest($method, $path, $data)->willReturn([]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         $client->sendRequest($method, $path, $data)->shouldBeCalled(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         $factory->create(Site::class, [])->willReturn($site); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         $this->patchSite($message); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     function it_should_delete_site(Client $client) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         $method = 'DELETE'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         $path   = 'sites/1'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         $client->sendRequest($method, $path)->shouldBeCalled(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         $this->deleteSite(1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     function it_should_get_platform_children( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         Client $client, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         ModelFactory $factory, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         PlatformChildrenListMessage $message | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         $message->getSiteId()->willReturn(1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         $message->build()->willReturn([]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         $method = 'GET'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         $path   = 'platform/1/children'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         $client->sendRequest($method, $path)->willReturn([]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         $client->sendRequest($method, $path)->shouldBeCalled(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         $factory->createMany(Site::class, [])->willReturn([]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         $this->getPlatformChildren($message); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 123 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 124 |  |  |  | 
            
                        
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.