BannerComposer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A compose() 0 18 4
1
<?php
2
3
namespace App\Http\ViewComposers;
4
5
use App\Repositories\BannerRepository;
6
use Illuminate\Contracts\View\View;
7
8
class BannerComposer extends Composer
9
{
10
    /**
11
     * @var BannerRepository
12
     */
13
    protected $banners;
14
15
    /**
16
     * BannerComposer constructor.
17
     * @param BannerRepository $bannerRepository
18
     */
19
    public function __construct(BannerRepository $bannerRepository)
20
    {
21
        $this->banners = $bannerRepository;
22
    }
23
24
    /**
25
     * @param View $view
26
     * @return $this
27
     */
28
    public function compose(View $view)
29
    {
30
        // Here template names is hardcoded, but here is easy to edit them, then go to templates and change variables there
31
32
        switch ($view->getName()){
33
            case "partials.banners.small":
34
                return $view->with('banners', $this->banners->getSmallAdBlocks(2));
35
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
36
37
            case "partials.banners.r_sidebar":
38
                return $view->with('banners', $this->banners->getRightSideBarAdBlocks(1));
39
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
40
41
            case "partials.banners.big":
42
                return $view->with('banners', $this->banners->getBigAdBlocks(2));
43
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
44
        }
45
    }
46
}