Completed
Push — master ( 07905b...790544 )
by yuuki
10s
created

PrimaryIndexRemoverCommand::getArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
ccs 2
cts 2
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
7
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
8
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
9
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
10
 * THE SOFTWARE.
11
 */
12
13
namespace Ytake\LaravelCouchbase\Console;
14
15
use Illuminate\Console\Command;
16
use Illuminate\Database\DatabaseManager;
17
use Symfony\Component\Console\Input\InputOption;
18
use Symfony\Component\Console\Input\InputArgument;
19
use Ytake\LaravelCouchbase\Database\CouchbaseConnection;
20
21
/**
22
 * Class PrimaryIndexRemoverCommand
23
 *
24
 * @author Yuuki Takezawa<[email protected]>
25
 */
26
class PrimaryIndexRemoverCommand extends Command
27
{
28
    /** @var string */
29
    protected $name = 'couchbase:drop-primary-index';
30
31
    /** @var string */
32
    protected $description = 'Drop the given primary index associated with the current bucket.';
33
34
    /** @var DatabaseManager */
35
    protected $databaseManager;
36
37
    /** @var string */
38
    protected $defaultDatabase = 'couchbase';
39
40
    /**
41
     * IndexFinderCommand constructor.
42
     *
43
     * @param DatabaseManager $databaseManager
44
     */
45 1
    public function __construct(DatabaseManager $databaseManager)
46
    {
47 1
        $this->databaseManager = $databaseManager;
48 1
        parent::__construct();
49 1
    }
50
51
    /**
52
     * @return string[]
53
     */
54 1
    protected function getArguments()
55
    {
56
        return [
57 1
            ['bucket', InputArgument::REQUIRED, 'Represents a bucket connection.'],
58
        ];
59
    }
60
61
    /**
62
     * Get the console command options.
63
     *
64
     * @return array
65
     */
66 1 View Code Duplication
    protected function getOptions()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
    {
68
        return [
69 1
            ['database', 'db', InputOption::VALUE_REQUIRED, 'The database connection to use.', $this->defaultDatabase],
70
            ['name', null, InputOption::VALUE_REQUIRED, 'the custom name for the primary index.', '#primary'],
71
            [
72
                'ignore',
73
                'ig',
74
                InputOption::VALUE_NONE,
75
                'if a primary index already exists, an exception will be thrown unless this is set to true.',
76
            ],
77
        ];
78
    }
79
80
    /**
81
     * Execute the console command
82
     */
83 1 View Code Duplication
    public function fire()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
84
    {
85
        /** @var \Illuminate\Database\Connection|CouchbaseConnection $connection */
86 1
        $connection = $this->databaseManager->connection($this->option('database'));
0 ignored issues
show
Bug introduced by
It seems like $this->option('database') targeting Illuminate\Console\Command::option() can also be of type array; however, Illuminate\Database\DatabaseManager::connection() does only seem to accept string|null, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
87 1
        if ($connection instanceof CouchbaseConnection) {
88 1
            $bucket = $connection->openBucket($this->argument('bucket'));
0 ignored issues
show
Bug introduced by
It seems like $this->argument('bucket') targeting Illuminate\Console\Command::argument() can also be of type array; however, Ytake\LaravelCouchbase\D...onnection::openBucket() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
89 1
            $bucket->manager()->dropN1qlPrimaryIndex(
90 1
                $this->option('name'),
91 1
                $this->option('ignore')
92
            );
93 1
            $this->info("dropped PRIMARY INDEX [{$this->option('name')}] for [{$this->argument('bucket')}] bucket.");
94
        }
95
96 1
        return;
97
    }
98
}
99