Completed
Push — master ( 91bd85...f52cfe )
by Camilo
02:46
created

PollOptionArray   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 3
1
<?php
2
declare(strict_types=1);
3
4
namespace unreal4u\TelegramAPI\Telegram\Types\Custom;
5
6
use Psr\Log\LoggerInterface;
7
use unreal4u\TelegramAPI\Abstracts\TraversableCustomType;
8
use unreal4u\TelegramAPI\Telegram\Types\PollOption;
9
use function count;
10
11
/**
12
 * Used for methods that will return an array of messages
13
 */
14
class PollOptionArray extends TraversableCustomType
15
{
16
    public function __construct(array $data = null, LoggerInterface $logger = null)
17
    {
18
        if (count($data) !== 0) {
19
            foreach ($data as $telegramResponse) {
0 ignored issues
show
Bug introduced by
The expression $data of type null|array 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...
20
                // Create an actual Update object and fill the array
21
                $this->data[] = new PollOption($telegramResponse, $logger);
22
            }
23
        }
24
    }
25
}
26