Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
CheckTableExistsCommand
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 buildOptionParser
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2declare(strict_types=1);
3
4namespace App\Command;
5
6use App\Utility\DatabaseUtility;
7use Cake\Command\Command;
8use Cake\Console\Arguments;
9use Cake\Console\ConsoleIo;
10use Cake\Console\ConsoleOptionParser;
11
12/**
13 * CheckTableExists command.
14 */
15class CheckTableExistsCommand extends Command
16{
17    /**
18     * Hook method for defining this command's option parser.
19     *
20     * @param \Cake\Console\ConsoleOptionParser $parser The parser to be defined
21     * @return \Cake\Console\ConsoleOptionParser The built parser.
22     */
23    public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
24    {
25        $parser
26            ->setDescription('Check if a table exists in the database')
27            ->addArgument('table', [
28                'help' => 'The name of the table to check',
29                'required' => true,
30            ]);
31
32        return $parser;
33    }
34
35    /**
36     * Implement this method with your command's logic.
37     *
38     * @param \Cake\Console\Arguments $args The command arguments.
39     * @param \Cake\Console\ConsoleIo $io The console io
40     * @return int|null The exit code or null for success
41     */
42    public function execute(Arguments $args, ConsoleIo $io): ?int
43    {
44        $tableName = $args->getArgument('table');
45
46        if (DatabaseUtility::tableExists($tableName)) {
47            return static::CODE_SUCCESS;
48        } else {
49            return static::CODE_ERROR;
50        }
51    }
52}