InsertQueryStringifier::initBuild()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace BenTools\Where\InsertQuery;
5
6
class InsertQueryStringifier
7
{
8
9
    /**
10
     * @param InsertQueryBuilder $query
11
     * @return array
12
     */
13
    private static function initBuild(InsertQueryBuilder $query): array
14
    {
15
        return \array_merge([$query->mainKeyword], $query->flags);
0 ignored issues
show
Documentation introduced by
The property $mainKeyword is declared private in BenTools\Where\InsertQuery\InsertQueryBuilder. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property $flags is declared private in BenTools\Where\InsertQuery\InsertQueryBuilder. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
16
    }
17
18
    /**
19
     * @param InsertQueryBuilder $insertQuery
20
     * @param array              $parts
21
     */
22
    private static function buildTable(InsertQueryBuilder $insertQuery, array &$parts)
23
    {
24
        if (null !== $insertQuery->table) {
0 ignored issues
show
Documentation introduced by
The property $table is declared private in BenTools\Where\InsertQuery\InsertQueryBuilder. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
25
            $parts[] = \sprintf('INTO %s', $insertQuery->escape($insertQuery->table));
0 ignored issues
show
Documentation introduced by
The property $table is declared private in BenTools\Where\InsertQuery\InsertQueryBuilder. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
26
        }
27
    }
28
29
    /**
30
     * @param InsertQueryBuilder $insertQuery
31
     * @param array              $parts
32
     */
33
    private static function buildColumns(InsertQueryBuilder $insertQuery, array &$parts)
34
    {
35
        $columns = $insertQuery->getColumns();
36
        if (null !== $columns) {
37
            $parts[] = \sprintf('(%s)', \implode(', ', \array_map([$insertQuery, 'escape'], $columns)));
38
        }
39
    }
40
41
    /**
42
     * @param InsertQueryBuilder $insertQuery
43
     * @param array              $parts
44
     */
45
    private static function buildValues(InsertQueryBuilder $insertQuery, array &$parts)
46
    {
47
        $columns = $insertQuery->getColumns();
48
49
        $parts[] = 'VALUES';
50
51
        $nbColumns = \count($columns);
52
        $nbValues = \count($insertQuery->values);
0 ignored issues
show
Documentation introduced by
The property $values is declared private in BenTools\Where\InsertQuery\InsertQueryBuilder. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
53
        $pattern = \sprintf('(%s)', \implode(', ', \array_fill(0, $nbColumns, '?')));
54
        $valueParts = \array_fill(0, $nbValues, $pattern);
55
56
        $parts[] = \implode(', ', $valueParts);
57
    }
58
59
    /**
60
     * @param InsertQueryBuilder $insertQuery
61
     * @param array              $parts
62
     */
63
    private static function buildDuplicateConditions(InsertQueryBuilder $insertQuery, array &$parts)
64
    {
65
        $duplicateConditions = $insertQuery->onDuplicate;
0 ignored issues
show
Documentation introduced by
The property $onDuplicate is declared private in BenTools\Where\InsertQuery\InsertQueryBuilder. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
66
        if ([] !== $duplicateConditions && null !== $duplicateConditions) {
67
            $parts[] = 'ON DUPLICATE KEY UPDATE';
68
            $updateParts = [];
69
            \array_walk($duplicateConditions, function ($value, $key) use ($insertQuery, &$updateParts) {
70
                $updateParts[] = \sprintf('%s = %s', $insertQuery->escape($key), $value);
71
            });
72
73
            $parts[] = \implode(', ', $updateParts);
74
        }
75
    }
76
77
    /**
78
     * @param InsertQueryBuilder $insertQuery
79
     * @return string
80
     */
81
    public static function stringify(InsertQueryBuilder $insertQuery): string
82
    {
83
        $parts = self::initBuild($insertQuery);
84
        self::buildTable($insertQuery, $parts);
85
        self::buildColumns($insertQuery, $parts);
86
        self::buildValues($insertQuery, $parts);
87
        self::buildDuplicateConditions($insertQuery, $parts);
88
        return \implode(' ', $parts) . $insertQuery->end;
0 ignored issues
show
Documentation introduced by
The property $end is declared private in BenTools\Where\InsertQuery\InsertQueryBuilder. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
89
    }
90
}
91