BannerRepository   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 43.64 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 24
loc 55
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getBigAdBlocks() 8 8 2
A getSmallAdBlocks() 8 8 2
A getModel() 0 4 1
A getRightSideBarAdBlocks() 8 8 2

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\Repositories;
4
5
use App\Banner;
6
7
class BannerRepository extends Repository
8
{
9
    /**
10
     * @return Banner
11
     */
12
    public function getModel()
13
    {
14
        return new Banner();
15
    }
16
17
    /**
18
     * Get ad-blocks for extended banners block.
19
     *
20
     * @param $count
21
     * @return mixed
22
     */
23 View Code Duplication
    public function getBigAdBlocks($count = null)
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...
24
    {
25
        return self::getModel()
0 ignored issues
show
Documentation Bug introduced by
The method take does not exist on object<App\Banner>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
26
            ->take(isset($count) ? $count : 2)
27
            ->active()
28
            ->orderBy('created_at', self::DESC)
29
            ->get();
30
    }
31
32
    /**
33
     * Get small adblocks for homepage.
34
     *
35
     * @param null $count
36
     * @return mixed
37
     */
38 View Code Duplication
    public function getSmallAdBlocks($count = null)
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...
39
    {
40
        return self::getModel()
0 ignored issues
show
Documentation Bug introduced by
The method take does not exist on object<App\Banner>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
41
            ->take(isset($count) ? $count : 2)
42
            ->active()
43
            ->orderBy('created_at', self::DESC)
44
            ->get();
45
    }
46
47
    /**
48
     * Get adblocks for right sidebar of homepage.
49
     *
50
     * @param null $count
51
     * @return mixed
52
     */
53 View Code Duplication
    public function getRightSideBarAdBlocks($count = null)
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...
54
    {
55
        return self::getModel()
0 ignored issues
show
Documentation Bug introduced by
The method take does not exist on object<App\Banner>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
56
            ->take(isset($count) ? $count : 1)
57
            ->active()
58
            ->orderBy('created_at', self::ASC)
59
            ->get();
60
    }
61
}