Completed
Pull Request — master (#259)
by Filip
10:28 queued 07:11
created

UnexpectedValueException::notACollection()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 6
rs 9.4285
cc 2
eloc 3
nc 2
nop 2
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 Doctrine;
14
15
16
17
/**
18
 * @author Filip Procházka <[email protected]>
19
 */
20
interface Exception
21
{
22
23
}
24
25
26
27
/**
28
 * @author Filip Procházka <[email protected]>
29
 */
30
class InvalidStateException extends \RuntimeException implements Exception
31
{
32
33
}
34
35
36
37
/**
38
 * @author Filip Procházka <[email protected]>
39
 */
40
class InvalidArgumentException extends \InvalidArgumentException implements Exception
41
{
42
43
}
44
45
46
47
/**
48
 * @author Filip Procházka <[email protected]>
49
 */
50
class NotSupportedException extends \LogicException implements Exception
51
{
52
53
}
54
55
56
57
/**
58
 * @author Filip Procházka <[email protected]>
59
 */
60
class StaticClassException extends \LogicException implements Exception
61
{
62
63
}
64
65
66
67
/**
68
 * The exception that is thrown when a requested method or operation is not implemented.
69
 */
70
class NotImplementedException extends \LogicException implements Exception
71
{
72
73
}
74
75
76
77
/**
78
 * When class is not found
79
 */
80
class MissingClassException extends \LogicException implements Exception
81
{
82
83
}
84
85
86
87
/**
88
 * @author Filip Procházka <[email protected]>
89
 */
90
class UnexpectedValueException extends \UnexpectedValueException implements Exception
91
{
92
93
}
94
95
96
97
/**
98
 * @author Filip Procházka <[email protected]>
99
 * @deprecated
100
 */
101
class DBALException extends \RuntimeException implements Exception
102
{
103
104
	/**
105
	 * @var string
106
	 */
107
	public $query;
108
109
	/**
110
	 * @var array
111
	 */
112
	public $params = [];
113
114
	/**
115
	 * @var \Doctrine\DBAL\Connection
116
	 */
117
	public $connection;
118
119
120
121
	/**
122
	 * @param \Exception $previous
123
	 * @param string $query
124
	 * @param array $params
125
	 * @param \Doctrine\DBAL\Connection $connection
126
	 * @param string $message
127
	 */
128
	public function __construct($previous, $query = NULL, $params = [], Doctrine\DBAL\Connection $connection = NULL, $message = NULL)
129
	{
130
		parent::__construct($message ?: $previous->getMessage(), $previous->getCode(), $previous);
131
		$this->query = $query;
132
		$this->params = $params;
133
		$this->connection = $connection;
134
	}
135
136
137
138
	/**
139
	 * This is just a paranoia, hopes no one actually serializes exceptions.
140
	 *
141
	 * @return array
142
	 */
143
	public function __sleep()
144
	{
145
		return ['message', 'code', 'file', 'line', 'errorInfo', 'query', 'params'];
146
	}
147
148
}
149
150
151
152
/**
153
 * @author Filip Procházka <[email protected]>
154
 * @deprecated
155
 */
156
class DuplicateEntryException extends DBALException
0 ignored issues
show
Deprecated Code introduced by
The class Kdyby\Doctrine\DBALException has been deprecated.

This class, trait or interface has been deprecated.

Loading history...
157
{
158
159
	/**
160
	 * @var array
161
	 */
162
	public $columns;
163
164
165
166
	/**
167
	 * @param \Exception $previous
168
	 * @param array $columns
169
	 * @param string $query
170
	 * @param array $params
171
	 * @param \Doctrine\DBAL\Connection $connection
172
	 */
173
	public function __construct($previous, $columns = [], $query = NULL, $params = [], Doctrine\DBAL\Connection $connection = NULL)
174
	{
175
		parent::__construct($previous, $query, $params, $connection);
176
		$this->columns = $columns;
177
	}
178
179
180
181
	/**
182
	 * @return array
183
	 */
184
	public function __sleep()
185
	{
186
		return array_merge(parent::__sleep(), ['columns']);
187
	}
188
189
}
190
191
192
193
/**
194
 * @author Filip Procházka <[email protected]>
195
 * @deprecated
196
 */
197
class EmptyValueException extends DBALException
0 ignored issues
show
Deprecated Code introduced by
The class Kdyby\Doctrine\DBALException has been deprecated.

This class, trait or interface has been deprecated.

Loading history...
198
{
199
200
	/**
201
	 * @var string
202
	 */
203
	public $column;
204
205
206
207
	/**
208
	 * @param \Exception $previous
209
	 * @param string $column
210
	 * @param string $query
211
	 * @param array $params
212
	 * @param \Doctrine\DBAL\Connection $connection
213
	 */
214
	public function __construct($previous, $column = NULL, $query = NULL, $params = [], Doctrine\DBAL\Connection $connection = NULL)
215
	{
216
		parent::__construct($previous, $query, $params, $connection);
217
		$this->column = $column;
218
	}
219
220
221
222
	/**
223
	 * @return array
224
	 */
225
	public function __sleep()
226
	{
227
		return array_merge(parent::__sleep(), ['column']);
228
	}
229
230
}
231
232
233
234
/**
235
 * @author Filip Procházka <[email protected]>
236
 */
237
class QueryException extends \RuntimeException implements Exception
238
{
239
240
	/**
241
	 * @var \Doctrine\ORM\Query
242
	 */
243
	public $query;
244
245
246
247
	/**
248
	 * @param \Exception $previous
249
	 * @param \Doctrine\ORM\AbstractQuery $query
250
	 * @param string $message
251
	 */
252
	public function __construct($previous, Doctrine\ORM\AbstractQuery $query = NULL, $message = "")
253
	{
254
		parent::__construct($message ?: $previous->getMessage(), 0, $previous);
255
		$this->query = $query;
0 ignored issues
show
Documentation Bug introduced by
It seems like $query can also be of type object<Doctrine\ORM\AbstractQuery>. However, the property $query is declared as type object<Doctrine\ORM\Query>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
256
	}
257
258
}
259
260
261
262
/**
263
 * @author Filip Procházka <[email protected]>
264
 */
265
class BatchImportException extends \RuntimeException implements Exception
266
{
267
268
}
269
270
271
272
/**
273
 * @author Michael Moravec
274
 */
275
class ReadOnlyCollectionException extends NotSupportedException
276
{
277
	/**
278
	 * @throws ReadOnlyCollectionException
279
	 */
280
	public static function invalidAccess($what)
281
	{
282
		return new static('Could not ' . $what . ' read-only collection, write/modify operations are forbidden.');
283
	}
284
}
285