GenerateSite::handle()   B
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 78
Code Lines 64

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 64
nc 3
nop 0
dl 0
loc 78
rs 8.7853
c 1
b 0
f 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Chuckbe\Chuckcms\Commands;
4
5
use Chuckbe\Chuckcms\Chuck\SiteRepository;
6
use Illuminate\Console\Command;
7
8
class GenerateSite extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'chuckcms:generate-site';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'This command generates a new site entry.';
23
24
    /**
25
     * The site repository implementation.
26
     *
27
     * @var SiteRepository
28
     */
29
    protected $siteRepository;
30
31
    /**
32
     * Create a new command instance.
33
     *
34
     * @return void
35
     */
36
    public function __construct(SiteRepository $siteRepository)
37
    {
38
        parent::__construct();
39
40
        $this->siteRepository = $siteRepository;
41
    }
42
43
    /**
44
     * Execute the console command.
45
     *
46
     * @return mixed
47
     */
48
    public function handle()
49
    {
50
        $name = $this->ask('What is name of the site? ');
51
        $slug = $this->ask('What is the unique slug of the site? ');
52
        $domain = $this->ask('What will be the domain of this site? E.G. http://google.be ');
53
54
        // Validate user input
55
        $this->info('Validating your information and generating a new site...');
56
57
        $data = [
58
            'name'    => $name,
59
            'slug'    => $slug,
60
            'domain'  => $domain,
61
        ];
62
63
        $rules = [
64
            'name'    => 'required|max:185',
65
            'slug'    => 'required|unique:sites',
66
            'domain'  => 'required|min:11',
67
        ];
68
69
        $validator = \Validator::make($data, $rules);
70
71
        if ($validator->fails()) {
72
            $messages = $validator->errors();
73
            foreach ($messages->all() as $message) {
74
                $this->error($message);
75
            }
76
        } else {
77
            $settings = [];
78
            $settings['company']['name'] = 'ChuckCMS';
79
            $settings['company']['vat'] = 'BE0000.000.000';
80
            $settings['company']['street'] = 'Berlaarsestraat';
81
            $settings['company']['housenumber'] = '10';
82
            $settings['company']['postalcode'] = '2500';
83
            $settings['company']['city'] = 'Lier';
84
            $settings['company']['email'] = '[email protected]';
85
            $settings['company']['tel'] = '0470 12 34 56';
86
            $settings['socialmedia']['facebook'] = 'https://facebook.com/chuckcmsmedia';
87
            $settings['socialmedia']['twitter'] = 'https://twitter.com/chuckcms';
88
            $settings['socialmedia']['pinterest'] = 'https://pinterest.com/chuckcms';
89
            $settings['socialmedia']['instagram'] = 'https://instagram.com/chuckcms';
90
            $settings['socialmedia']['snapchat'] = 'https://snapchat.co/username';
91
            $settings['socialmedia']['googleplus'] = 'https://plus.google.com/+ChuckCMS';
92
            $settings['socialmedia']['tumblr'] = 'https://tumblr.com/chuckcms';
93
            $settings['socialmedia']['youtube'] = 'https://youtube.com/chuckcms';
94
            $settings['socialmedia']['vimeo'] = 'https://vimeo.com/chuckcms';
95
            $settings['integrations']['ga-id'] = null;
96
            $settings['integrations']['g-site-verification'] = null;
97
            $settings['favicon']['href'] = '/chuckbe/chuckcms/favicon.ico';
98
            $settings['logo']['href'] = '/chuckbe/chuckcms/chuckcms-logo.png';
99
            $settings['lang'] = 'nl,en';
100
            $settings['domain'] = $domain;
101
            // create the site
102
            $this->siteRepository->createFromArray([
103
                'name'     => $name,
104
                'slug'     => $slug,
105
                'domain'   => $domain,
106
                'settings' => $settings,
107
            ]);
108
109
            $this->info('.         .');
110
            $this->info('..         ..');
111
            $this->info('...         ...');
112
            $this->info('.... AWESOME ....');
113
            $this->info('...         ...');
114
            $this->info('..         ..');
115
            $this->info('.         .');
116
            $this->info('.         .');
117
            $this->info('..         ..');
118
            $this->info('...         ...');
119
            $this->info('....   JOB   ....');
120
            $this->info('...         ...');
121
            $this->info('..         ..');
122
            $this->info('.         .');
123
            $this->info(' ');
124
            $this->info('New site: '.$name.' ('.$domain.') generated successfully');
125
            $this->info(' ');
126
        }
127
    }
128
}
129