AllDbsCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 27
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 4 1
A execute() 0 7 2
1
<?php
2
3
/**
4
 * @file AllDbsCommand.php
5
 * @brief This file contains the AllDbsCommand class.
6
 * @details
7
 * @author Filippo F. Fadda
8
 */
9
10
11
namespace EoC\CLI\Command;
12
13
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
18
/**
19
 * @brief Displays information about the selected database.
20
 * @nosubgrouping
21
 */
22
class AllDbsCommand extends AbstractCommand {
23
24
25
  /**
26
   * @brief Configures the command.
27
   */
28
  protected function configure() {
29
    $this->setName("alldbs");
30
    $this->setDescription("Returns a list of all databases on this server");
31
  }
32
33
34
  /**
35
   * @brief Executes the command.
36
   * @param[in] InputInterface $input The input interface
37
   * @param[in] OutputInterface $output The output interface
38
   * @retval string Information about current database.
39
   */
40
  protected function execute(InputInterface $input, OutputInterface $output) {
41
    $couch = $this->getConnection();
42
43
    $dbs = $couch->getAllDbs();
44
    foreach ($dbs as $db)
0 ignored issues
show
Bug introduced by
The expression $dbs of type object|integer|double|string|array|boolean|null is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
45
      echo $db.PHP_EOL;
46
  }
47
48
}