Completed
Push — master ( 30ea98...ad161f )
by Jake
02:20
created

SEOGenerator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 100
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B generateSEO() 0 34 3
B favicon() 0 30 1
A make() 0 23 2
A get() 0 4 1
1
<?php
2
3
namespace MeestorHok\Blue;
4
5
use Artesaos\SEOTools\Facades\SEOTools as SEO;
6
use Request;
7
8
class SEOGenerator
9
{
10
    // DIR for icons
11
    const FAVICONS = '/img/icons';
12
    
13
    public static function generateSEO (array $page)
14
    {
15
        SEO::metatags()
16
            ->setTitleDefault($page['title-description'])
17
            ->setTitleSeparator($page['title-spacer'])
18
            ->setTitle($page['title'])
19
            ->setDescription($page['description'])
20
            ->setCanonical(Request::url())
21
            ->addMeta('copyright', $page['copyright'])
22
            ->addMeta('robots', $page['robots'])
23
            ->addMeta('HandheldFriendly', 'True')
24
            ->addMeta('MobileOptimized', '320')
25
            ->addMeta('X-UA-Compatible', 'IE=edge', 'http-equiv')
26
            ->addMeta('viewport', 'width=device-width, initial-scale=1, shrink-to-fit=no');
27
        SEO::opengraph()
28
            ->setTitle($page['title'] . $page['title-spacer'] . $page['title-description'])
29
            ->setDescription($page['description'])
30
            ->setUrl(Request::url())
31
            ->addProperty('locale', 'en_US')
32
            ->addProperty('type', 'website');
33
        SEO::twitter()
34
            ->setSite($page['twitter'])
35
            ->setTitle($page['title'] . $page['title-spacer'] . $page['title-description'])
36
            ->setDescription($page['description'])
37
            ->setType('summary')
38
            ->setUrl(Request::url());
39
        foreach ($page['images'] as $image) {
40
            SEO::opengraph()->addImage(asset($image['uri']));
41
            SEO::twitter()->addImage(asset($image['uri']));
42
        }
43
        foreach ($page['keywords'] as $keyword) {
44
            SEO::metatags()->addKeyword($keyword);
45
        }
46
    }
47
    
48
    public static function favicon () {
49
        $colors = [
50
            'safari-pinned' => '#5bbad5',
51
            'ms-tile' => '#da532c',
52
            'theme' => '#ec500e'
53
        ];
54
        
55
        return
56
            '<link rel="apple-touch-icon" sizes="57x57" href="' . asset(self::FAVICONS . '/apple-touch-icon-57x57.png') . '">' .
57
            '<link rel="apple-touch-icon" sizes="60x60" href="' . asset(self::FAVICONS . '/apple-touch-icon-60x60.png') . '">' .
58
            '<link rel="apple-touch-icon" sizes="72x72" href="' . asset(self::FAVICONS . '/apple-touch-icon-72x72.png') . '">' .
59
            '<link rel="apple-touch-icon" sizes="76x76" href="' . asset(self::FAVICONS . '/apple-touch-icon-76x76.png') . '">' .
60
            '<link rel="apple-touch-icon" sizes="114x114" href="' . asset(self::FAVICONS . '/apple-touch-icon-114x114.png') . '">' .
61
            '<link rel="apple-touch-icon" sizes="120x120" href="' . asset(self::FAVICONS . '/apple-touch-icon-120x120.png') . '">' .
62
            '<link rel="apple-touch-icon" sizes="144x144" href="' . asset(self::FAVICONS . '/apple-touch-icon-144x144.png') . '">' .
63
            '<link rel="apple-touch-icon" sizes="152x152" href="' . asset(self::FAVICONS . '/apple-touch-icon-152x152.png') . '">' .
64
            '<link rel="apple-touch-icon" sizes="180x180" href="' . asset(self::FAVICONS . '/apple-touch-icon-180x180.png') . '">' .
65
            '<link rel="icon" type="image/png" href="' . asset(self::FAVICONS . '/favicon-16x16.png') . '" sizes="16x16">' .
66
            '<link rel="icon" type="image/png" href="' . asset(self::FAVICONS . '/favicon-32x32.png') . '" sizes="32x32">' .
67
            '<link rel="icon" type="image/png" href="' . asset(self::FAVICONS . '/favicon-96x96.png') . '" sizes="96x96">' .
68
            '<link rel="icon" type="image/png" href="' . asset(self::FAVICONS . '/favicon-194x194.png') . '" sizes="194x194">' .
69
            '<link rel="icon" type="image/png" href="' . asset(self::FAVICONS . '/android-chrome-192x192.png') . '" sizes="192x192">' .
70
            '<link rel="manifest" href="' . asset(self::FAVICONS . '/manifest.json') . '">' .
71
            '<link rel="mask-icon" href="' . asset(self::FAVICONS . '/safari-pinned-tab.svg') . '" color="' . $colors['safari-pinned'] . '">' .
72
            '<link rel="shortcut icon" href="' . asset(self::FAVICONS . '/favicon.ico') . '">' .
73
            '<meta name="msapplication-TileColor" content="' . $colors['ms-tile'] . '">' .
74
            '<meta name="msapplication-TileImage" content="' . asset(self::FAVICONS . '/mstile-144x144.png') . '">' .
75
            '<meta name="msapplication-config" content="' . asset(self::FAVICONS . '/browserconfig.xml') . '">' .
76
            '<meta name="theme-color" content="' . $colors['theme'] . '">';
77
    }
78
    
79
    public static function make (array $details, $view = null)
80
    {
81
        $defaults = [
82
            'title' => 'Home',
83
            'title-spacer' => ' &#8211; ',
84
            'title-description' => 'Laravel Blue',
85
            'keywords' => array_collapse([['home'], ['laravel', 'blue', 'cms', 'meestorhok']]),
86
            'description' => 'This amazing site was created by Laravel Blue!',
87
            'images' => [],
88
            'twitter' => '@BlueCMS',
89
            'copyright' => '© 2016 Laravel Blue',
90
            'favicons' => '/img/icons',
91
            'robots' => 'index,follow'
92
        ];
93
        
94
        $data = array_replace($defaults, $details);
95
        
96
        self::generateSEO($data);
97
        
98
        if (!is_null($view)) {
99
            return view($view)->with('seo', self::get());
0 ignored issues
show
Bug introduced by
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
100
        }
101
    }
102
    
103
    public static function get ()
104
    {
105
        return str_replace(PHP_EOL, '', SEO::generate()) . self::favicon();
106
    }
107
}