Passed
Pull Request — 2.x (#135)
by Aleksei
18:00
created

CompileJson::compile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 10
rs 10
1
<?php
2
3
/**
4
 * This file is part of Cycle ORM package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Cycle\Database\Driver\Postgres\Injection;
13
14
class CompileJson extends PostgresJsonExpression
15
{
16
    /**
17
     * @param non-empty-string $statement
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
18
     *
19
     * @return non-empty-string
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
20
     */
21
    protected function compile(string $statement): string
22
    {
23
        $wrappedPath = $this->getWrappedPath($statement);
24
        $attribute = \array_pop($wrappedPath);
25
26
        if (!empty($wrappedPath)) {
27
            return $this->getField($statement) . '->' . \implode('->', $wrappedPath) . '->>' . $attribute;
28
        }
29
30
        return $this->getField($statement) . '->>' . $attribute;
31
    }
32
}
33