DomainCommandTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
eloc 15
dl 0
loc 39
rs 10
c 3
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDomainName() 0 7 2
A getDomainNameForRepo() 0 18 2
1
<?php
2
3
namespace Salah3id\Domains\Traits;
4
5
use Symfony\Component\Console\Question\ChoiceQuestion;
6
7
trait DomainCommandTrait
8
{
9
    /**
10
     * Get the domain name.
11
     *
12
     * @return string
13
     */
14
    public function getDomainName()
15
    {
16
        $domain = $this->argument('domain') ?: app('domains')->getUsedNow();
0 ignored issues
show
Bug introduced by
It seems like argument() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

16
        $domain = $this->/** @scrutinizer ignore-call */ argument('domain') ?: app('domains')->getUsedNow();
Loading history...
17
18
        $domain = app('domains')->findOrFail($domain);
19
20
        return $domain->getStudlyName();
21
    }
22
23
    /**
24
     * Get the domain name for Repository Commands.
25
     *
26
     * @return string
27
     */
28
    public function getDomainNameForRepo()
29
    {
30
        try {
31
            $domain = app('domains')->getUsedNow();
32
33
            $domain = app('domains')->findOrFail($domain)->getStudlyName();
34
35
        } catch (\Throwable $th) {
36
            $helper = $this->getHelper('question');
0 ignored issues
show
Bug introduced by
It seems like getHelper() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
            /** @scrutinizer ignore-call */ 
37
            $helper = $this->getHelper('question');
Loading history...
37
            $question = new ChoiceQuestion(
38
                'Select Domain :',
39
                array_values($this->laravel['domains']->all()),
40
                0
41
            );
42
            $question->setErrorMessage('Domain %s is invalid.');
43
            $domain = $helper->ask($this->input, $this->output, $question);;
44
        }
45
        return $domain;
46
    }
47
}
48