HookController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 36 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 6
dl 9
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fetchGuilds() 9 9 2
A fetchCharacters() 0 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace App\Controller\API;
4
5
use App\Entity\Guild;
6
use App\Entity\Setting;
7
use App\Handler\ApiHandler;
8
use App\Utils\AbstractCrawler;
9
use App\Utils\CharacterCrawler;
10
use App\Utils\GuildCrawler;
11
use FOS\RestBundle\Controller\FOSRestController;
12
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
13
use Nelmio\ApiDocBundle\Annotation\Model;
14
use Swagger\Annotations as SWG;
15
use Symfony\Component\HttpFoundation\JsonResponse;
16
17
/**
18
 * @Route("/api/hook")
19
 */
20
class HookController extends FOSRestController
21
{
22
    /**
23
     * @Route("/fetch-guild", name="api_guild_collect_users")
24
     */
25 View Code Duplication
    public function fetchGuilds(GuildCrawler $crawler)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
26
    {
27
        $guilds = $this->getDoctrine()->getRepository(Guild::class)->findAll();
28
        foreach ($guilds as $guild) {
29
            $crawler->crawl($guild);
30
        }
31
32
        return JsonResponse::create(['success']);
33
    }
34
    /**
35
     * @Route("/fetch-characters", name="api_collect_characters")
36
     */
37
    public function fetchCharacters(CharacterCrawler $crawler)
38
    {
39
        $settings = $this->getDoctrine()->getRepository(Setting::class)->findOneByCode('swgoh');
0 ignored issues
show
Bug introduced by
The method findOneByCode() does not exist on Doctrine\Common\Persistence\ObjectRepository. Did you maybe mean findOneBy()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
40
        $crawler->crawl($settings);
41
42
        return JsonResponse::create(['success']);
43
    }
44
}
45