InteractsWithUser   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 12
c 1
b 0
f 0
dl 0
loc 73
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getVendorFolderName() 0 5 1
A askUser() 0 7 2
A getPackageFolderName() 0 5 1
A getPackage() 0 5 2
A getVendor() 0 5 2
1
<?php
2
3
namespace Blok\LaravelPackageGenerator\Commands\Traits;
4
5
use Illuminate\Support\Str;
6
7
trait InteractsWithUser
8
{
9
    /**
10
     * Get vendor part of the namespace part.
11
     *
12
     * @param string $default
13
     *
14
     * @return string
15
     */
16
    protected function getVendor($default = '')
17
    {
18
        $vendor = $this->argument('vendor') ?: $default;
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

18
        $vendor = $this->/** @scrutinizer ignore-call */ argument('vendor') ?: $default;
Loading history...
19
20
        return $this->askUser('The vendor name?', $vendor);
21
    }
22
23
    /**
24
     * Get the name of package for the namespace.
25
     *
26
     * @param string $default
27
     *
28
     * @return string
29
     */
30
    protected function getPackage($default = '')
31
    {
32
        $package = $this->argument('package') ?: $default;
33
34
        return $this->askUser('The package name?', $package);
35
    }
36
37
    /**
38
     * Get vendor folder name.
39
     *
40
     * @param string $vendor
41
     *
42
     * @return string
43
     */
44
    protected function getVendorFolderName($vendor)
45
    {
46
        $vendorFolderName = Str::kebab($vendor);
47
48
        return $this->askUser('The vendor folder name?', $vendorFolderName);
49
    }
50
51
    /**
52
     * Get package folder name.
53
     *
54
     * @param string $package
55
     *
56
     * @return string
57
     */
58
    protected function getPackageFolderName($package)
59
    {
60
        $packageFolderName = Str::kebab($package);
61
62
        return $this->askUser('The package folder name?', $packageFolderName);
63
    }
64
65
    /**
66
     * Ask user.
67
     *
68
     * @param $question
69
     * @param $defaultValue
70
     *
71
     * @return string
72
     */
73
    protected function askUser($question, $defaultValue = '')
74
    {
75
        if ($this->option('interactive')) {
0 ignored issues
show
Bug introduced by
It seems like option() 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

75
        if ($this->/** @scrutinizer ignore-call */ option('interactive')) {
Loading history...
76
            return $this->ask($question, $defaultValue);
0 ignored issues
show
Bug introduced by
It seems like ask() 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

76
            return $this->/** @scrutinizer ignore-call */ ask($question, $defaultValue);
Loading history...
77
        }
78
79
        return $defaultValue;
80
    }
81
}
82