| 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\Factory\ModelFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Yproximite\Api\Model\TeamWorker\TeamWorker; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Yproximite\Api\Service\TeamWorkerService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Yproximite\Api\Message\TeamWorker\TeamWorkerPostMessage; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Yproximite\Api\Message\TeamWorker\TeamWorkerPatchMessage; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 14 |  | View Code Duplication | class TeamWorkerServiceSpec extends ObjectBehavior | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     function it_is_initializable() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |         $this->shouldHaveType(TeamWorkerService::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |     function let(Client $client, ModelFactory $factory) | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |         $this->beConstructedWith($client, $factory); | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     function it_should_post_team_worker( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         Client $client, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         ModelFactory $factory, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         TeamWorkerPostMessage $message, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         TeamWorker $teamWorker | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $message->getSiteId()->willReturn(1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $message->build()->willReturn([]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $method = 'POST'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $path   = 'sites/1/teams/workers'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $data   = ['api_team_worker' => []]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $client->sendRequest($method, $path, $data)->willReturn([]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $client->sendRequest($method, $path, $data)->shouldBeCalled(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $factory->create(TeamWorker::class, [])->willReturn($teamWorker); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $this->postTeamWorker($message); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     function it_should_patch_team_worker( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         Client $client, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         ModelFactory $factory, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         TeamWorkerPatchMessage $message, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         TeamWorker $teamWorker | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $message->getId()->willReturn(2); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $message->getSiteId()->willReturn(1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $message->build()->willReturn([]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $method = 'PATCH'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $path   = 'sites/1/teams/2/worker'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $data   = ['api_team_worker' => []]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $client->sendRequest($method, $path, $data)->willReturn([]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $client->sendRequest($method, $path, $data)->shouldBeCalled(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $factory->create(TeamWorker::class, [])->willReturn($teamWorker); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $this->patchTeamWorker($message); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 68 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 69 |  |  |  | 
            
                        
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.