Test Failed
Push — master ( ecd78b...d05c81 )
by Kirill
02:43
created

InputValue::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\SDL\Frontend\IR\Value;
11
12
/**
13
 * Class InputValue
14
 */
15
class InputValue extends AbstractValue
16
{
17
    /**
18
     * InputValue constructor.
19
     * @param iterable $values
20
     * @param int $offset
21
     */
22
    public function __construct(iterable $values, int $offset = 0)
23
    {
24
        parent::__construct($this->getCached($values), $offset);
25
    }
26
27
    /**
28
     * @param iterable $values
29
     * @return iterable
30
     */
31
    private function getCached(iterable $values): iterable
32
    {
33
        $result = [];
34
35
        foreach ($values as $k => $v) {
36
            $result[] = [$k, $v];
37
        }
38
39
        return $result;
40
    }
41
42
    /**
43
     * @return string
44
     */
45
    public function toString(): string
46
    {
47
        $result = [];
48
49
        /**
50
         * @var ValueInterface $key
51
         * @var ValueInterface $value
52
         */
53
        foreach ($this->getValue() as $key => $value) {
54
            $result[] = $key->toString() . ': ' . (string)$value;
0 ignored issues
show
Bug introduced by
The method toString cannot be called on $key (of type integer|string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
55
        }
56
57
        return \sprintf('{%s}', \implode(', ', $result));
58
    }
59
60
    /**
61
     * @return iterable
62
     */
63
    public function getValue(): iterable
64
    {
65
        foreach (parent::getValue() as [$key, $value]) {
66
            yield $key => $value;
0 ignored issues
show
Bug introduced by
The variable $key does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $value does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
67
        }
68
    }
69
}
70