|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the Kdyby (http://www.kdyby.org) |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (c) 2008 Filip Procházka ([email protected]) |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the file license.txt that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Kdyby\Doctrine; |
|
12
|
|
|
|
|
13
|
|
|
use Kdyby; |
|
14
|
|
|
use Nette; |
|
15
|
|
|
use Doctrine\DBAL\Types\Type; |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @author Filip Procházka <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class Helpers extends Nette\Object |
|
23
|
|
|
{ |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param QueryBuilder|NativeQueryBuilder $query |
|
28
|
|
|
* @param array $args |
|
29
|
|
|
* @return array |
|
30
|
|
|
*/ |
|
31
|
|
|
public static function separateParameters($query, array $args) |
|
32
|
|
|
{ |
|
33
|
|
|
for ($i = 0; array_key_exists($i, $args) && array_key_exists($i + 1, $args) && ($arg = $args[$i]); $i++) { |
|
34
|
|
|
if ( ! preg_match_all('~((\\:|\\?)(?P<name>[a-z0-9_]+))(?=(?:\\z|\\s|\\)))~i', $arg, $m)) { |
|
35
|
|
|
continue; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
$repeatedArgs = []; |
|
39
|
|
|
foreach ($m['name'] as $l => $name) { |
|
40
|
|
|
if (isset($repeatedArgs[$name])) { |
|
41
|
|
|
continue; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$value = $args[++$i]; |
|
45
|
|
|
$type = NULL; |
|
46
|
|
|
|
|
47
|
|
|
if ($value instanceof \DateTime || $value instanceof \DateTimeImmutable) { |
|
|
|
|
|
|
48
|
|
|
$type = Type::DATETIME; |
|
49
|
|
|
|
|
50
|
|
|
} elseif (is_array($value)) { |
|
51
|
|
|
$type = Connection::PARAM_STR_ARRAY; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$query->setParameter($name, $value, $type); |
|
55
|
|
|
$repeatedArgs[$name] = TRUE; |
|
56
|
|
|
unset($args[$i]); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return $args; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param \ReflectionProperty $property |
|
67
|
|
|
* @return int |
|
68
|
|
|
*/ |
|
69
|
|
|
public static function getPropertyLine(\ReflectionProperty $property) |
|
70
|
|
|
{ |
|
71
|
|
|
$class = $property->getDeclaringClass(); |
|
72
|
|
|
|
|
73
|
|
|
$context = 'file'; |
|
74
|
|
|
$contextBrackets = 0; |
|
75
|
|
|
foreach (token_get_all(file_get_contents($class->getFileName())) as $token) { |
|
76
|
|
|
if ($token === '{') { |
|
77
|
|
|
$contextBrackets += 1; |
|
78
|
|
|
|
|
79
|
|
|
} elseif ($token === '}') { |
|
80
|
|
|
$contextBrackets -= 1; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
if (!is_array($token)) { |
|
84
|
|
|
continue; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
if ($token[0] === T_CLASS) { |
|
88
|
|
|
$context = 'class'; |
|
89
|
|
|
$contextBrackets = 0; |
|
90
|
|
|
|
|
91
|
|
|
} elseif ($context === 'class' && $contextBrackets === 1 && $token[0] === T_VARIABLE) { |
|
92
|
|
|
if ($token[1] === '$' . $property->getName()) { |
|
93
|
|
|
return $token[2]; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
return NULL; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @param array $one |
|
105
|
|
|
* @param array $two |
|
106
|
|
|
* |
|
107
|
|
|
* @return array |
|
108
|
|
|
*/ |
|
109
|
|
|
public static function zipper(array $one, array $two) |
|
110
|
|
|
{ |
|
111
|
|
|
$output = []; |
|
112
|
|
|
while ($one && $two) { |
|
|
|
|
|
|
113
|
|
|
$output[] = array_shift($one); |
|
114
|
|
|
$output[] = array_shift($two); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
return array_merge($output, $one ? : [], $two ? : []); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
} |
|
121
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.