Completed
Push — master ( 8d6c09...33443d )
by Sam
05:30 queued 40s
created

ConnectionQuery   F

Complexity

Total Complexity 92

Size/Duplication

Total Lines 625
Duplicated Lines 49.28 %

Coupling/Cohesion

Components 3
Dependencies 15

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 92
c 1
b 0
f 0
lcom 3
cbo 15
dl 308
loc 625
rs 1.5

23 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 15 15 4
C findPk() 21 21 18
B findPkSimple() 22 22 6
A findPkComplex() 10 10 2
A findPks() 13 13 3
A filterByPrimaryKey() 0 5 1
A filterByPrimaryKeys() 0 5 1
B filterById() 22 22 6
A filterByInstanceName() 13 13 4
B filterByUserId() 22 22 6
A filterByPeer() 13 13 4
B filterByStarted() 22 22 6
A filterByType() 13 13 4
A filterByInstance() 16 16 4
B joinInstance() 23 23 4
A useInstanceQuery() 0 6 2
A filterByUser() 16 16 4
B joinUser() 23 23 4
A useUserQuery() 0 6 2
A prune() 0 8 2
A doDeleteAll() 20 20 2
B delete() 24 24 2

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like ConnectionQuery often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ConnectionQuery, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Jalle19\StatusManager\Database\Base;
4
5
use \Exception;
6
use \PDO;
7
use Jalle19\StatusManager\Database\Connection as ChildConnection;
8
use Jalle19\StatusManager\Database\ConnectionQuery as ChildConnectionQuery;
9
use Jalle19\StatusManager\Database\Map\ConnectionTableMap;
10
use Propel\Runtime\Propel;
11
use Propel\Runtime\ActiveQuery\Criteria;
12
use Propel\Runtime\ActiveQuery\ModelCriteria;
13
use Propel\Runtime\ActiveQuery\ModelJoin;
14
use Propel\Runtime\Collection\ObjectCollection;
15
use Propel\Runtime\Connection\ConnectionInterface;
16
use Propel\Runtime\Exception\PropelException;
17
18
/**
19
 * Base class that represents a query for the 'connection' table.
20
 *
21
 *
22
 *
23
 * @method     ChildConnectionQuery orderById($order = Criteria::ASC) Order by the id column
24
 * @method     ChildConnectionQuery orderByInstanceName($order = Criteria::ASC) Order by the instance_name column
25
 * @method     ChildConnectionQuery orderByUserId($order = Criteria::ASC) Order by the user_id column
26
 * @method     ChildConnectionQuery orderByPeer($order = Criteria::ASC) Order by the peer column
27
 * @method     ChildConnectionQuery orderByStarted($order = Criteria::ASC) Order by the started column
28
 * @method     ChildConnectionQuery orderByType($order = Criteria::ASC) Order by the type column
29
 *
30
 * @method     ChildConnectionQuery groupById() Group by the id column
31
 * @method     ChildConnectionQuery groupByInstanceName() Group by the instance_name column
32
 * @method     ChildConnectionQuery groupByUserId() Group by the user_id column
33
 * @method     ChildConnectionQuery groupByPeer() Group by the peer column
34
 * @method     ChildConnectionQuery groupByStarted() Group by the started column
35
 * @method     ChildConnectionQuery groupByType() Group by the type column
36
 *
37
 * @method     ChildConnectionQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
38
 * @method     ChildConnectionQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
39
 * @method     ChildConnectionQuery innerJoin($relation) Adds a INNER JOIN clause to the query
40
 *
41
 * @method     ChildConnectionQuery leftJoinWith($relation) Adds a LEFT JOIN clause and with to the query
42
 * @method     ChildConnectionQuery rightJoinWith($relation) Adds a RIGHT JOIN clause and with to the query
43
 * @method     ChildConnectionQuery innerJoinWith($relation) Adds a INNER JOIN clause and with to the query
44
 *
45
 * @method     ChildConnectionQuery leftJoinInstance($relationAlias = null) Adds a LEFT JOIN clause to the query using the Instance relation
46
 * @method     ChildConnectionQuery rightJoinInstance($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Instance relation
47
 * @method     ChildConnectionQuery innerJoinInstance($relationAlias = null) Adds a INNER JOIN clause to the query using the Instance relation
48
 *
49
 * @method     ChildConnectionQuery joinWithInstance($joinType = Criteria::INNER_JOIN) Adds a join clause and with to the query using the Instance relation
50
 *
51
 * @method     ChildConnectionQuery leftJoinWithInstance() Adds a LEFT JOIN clause and with to the query using the Instance relation
52
 * @method     ChildConnectionQuery rightJoinWithInstance() Adds a RIGHT JOIN clause and with to the query using the Instance relation
53
 * @method     ChildConnectionQuery innerJoinWithInstance() Adds a INNER JOIN clause and with to the query using the Instance relation
54
 *
55
 * @method     ChildConnectionQuery leftJoinUser($relationAlias = null) Adds a LEFT JOIN clause to the query using the User relation
56
 * @method     ChildConnectionQuery rightJoinUser($relationAlias = null) Adds a RIGHT JOIN clause to the query using the User relation
57
 * @method     ChildConnectionQuery innerJoinUser($relationAlias = null) Adds a INNER JOIN clause to the query using the User relation
58
 *
59
 * @method     ChildConnectionQuery joinWithUser($joinType = Criteria::INNER_JOIN) Adds a join clause and with to the query using the User relation
60
 *
61
 * @method     ChildConnectionQuery leftJoinWithUser() Adds a LEFT JOIN clause and with to the query using the User relation
62
 * @method     ChildConnectionQuery rightJoinWithUser() Adds a RIGHT JOIN clause and with to the query using the User relation
63
 * @method     ChildConnectionQuery innerJoinWithUser() Adds a INNER JOIN clause and with to the query using the User relation
64
 *
65
 * @method     \Jalle19\StatusManager\Database\InstanceQuery|\Jalle19\StatusManager\Database\UserQuery endUse() Finalizes a secondary criteria and merges it with its primary Criteria
66
 *
67
 * @method     ChildConnection findOne(ConnectionInterface $con = null) Return the first ChildConnection matching the query
68
 * @method     ChildConnection findOneOrCreate(ConnectionInterface $con = null) Return the first ChildConnection matching the query, or a new ChildConnection object populated from the query conditions when no match is found
69
 *
70
 * @method     ChildConnection findOneById(int $id) Return the first ChildConnection filtered by the id column
71
 * @method     ChildConnection findOneByInstanceName(string $instance_name) Return the first ChildConnection filtered by the instance_name column
72
 * @method     ChildConnection findOneByUserId(int $user_id) Return the first ChildConnection filtered by the user_id column
73
 * @method     ChildConnection findOneByPeer(string $peer) Return the first ChildConnection filtered by the peer column
74
 * @method     ChildConnection findOneByStarted(string $started) Return the first ChildConnection filtered by the started column
75
 * @method     ChildConnection findOneByType(string $type) Return the first ChildConnection filtered by the type column *
76
77
 * @method     ChildConnection requirePk($key, ConnectionInterface $con = null) Return the ChildConnection by primary key and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
78
 * @method     ChildConnection requireOne(ConnectionInterface $con = null) Return the first ChildConnection matching the query and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
79
 *
80
 * @method     ChildConnection requireOneById(int $id) Return the first ChildConnection filtered by the id column and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
81
 * @method     ChildConnection requireOneByInstanceName(string $instance_name) Return the first ChildConnection filtered by the instance_name column and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
82
 * @method     ChildConnection requireOneByUserId(int $user_id) Return the first ChildConnection filtered by the user_id column and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
83
 * @method     ChildConnection requireOneByPeer(string $peer) Return the first ChildConnection filtered by the peer column and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
84
 * @method     ChildConnection requireOneByStarted(string $started) Return the first ChildConnection filtered by the started column and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
85
 * @method     ChildConnection requireOneByType(string $type) Return the first ChildConnection filtered by the type column and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
86
 *
87
 * @method     ChildConnection[]|ObjectCollection find(ConnectionInterface $con = null) Return ChildConnection objects based on current ModelCriteria
88
 * @method     ChildConnection[]|ObjectCollection findById(int $id) Return ChildConnection objects filtered by the id column
89
 * @method     ChildConnection[]|ObjectCollection findByInstanceName(string $instance_name) Return ChildConnection objects filtered by the instance_name column
90
 * @method     ChildConnection[]|ObjectCollection findByUserId(int $user_id) Return ChildConnection objects filtered by the user_id column
91
 * @method     ChildConnection[]|ObjectCollection findByPeer(string $peer) Return ChildConnection objects filtered by the peer column
92
 * @method     ChildConnection[]|ObjectCollection findByStarted(string $started) Return ChildConnection objects filtered by the started column
93
 * @method     ChildConnection[]|ObjectCollection findByType(string $type) Return ChildConnection objects filtered by the type column
94
 * @method     ChildConnection[]|\Propel\Runtime\Util\PropelModelPager paginate($page = 1, $maxPerPage = 10, ConnectionInterface $con = null) Issue a SELECT query based on the current ModelCriteria and uses a page and a maximum number of results per page to compute an offset and a limit
95
 *
96
 */
97
abstract class ConnectionQuery extends ModelCriteria
98
{
99
    protected $entityNotFoundExceptionClass = '\\Propel\\Runtime\\Exception\\EntityNotFoundException';
100
101
    /**
102
     * Initializes internal state of \Jalle19\StatusManager\Database\Base\ConnectionQuery object.
103
     *
104
     * @param     string $dbName The database name
105
     * @param     string $modelName The phpName of a model, e.g. 'Book'
106
     * @param     string $modelAlias The alias for the model in this query, e.g. 'b'
107
     */
108
    public function __construct($dbName = 'tvheadend_status_manager', $modelName = '\\Jalle19\\StatusManager\\Database\\Connection', $modelAlias = null)
109
    {
110
        parent::__construct($dbName, $modelName, $modelAlias);
111
    }
112
113
    /**
114
     * Returns a new ChildConnectionQuery object.
115
     *
116
     * @param     string $modelAlias The alias of a model in the query
117
     * @param     Criteria $criteria Optional Criteria to build the query from
118
     *
119
     * @return ChildConnectionQuery
120
     */
121 View Code Duplication
    public static function create($modelAlias = null, Criteria $criteria = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
122
    {
123
        if ($criteria instanceof ChildConnectionQuery) {
124
            return $criteria;
125
        }
126
        $query = new ChildConnectionQuery();
127
        if (null !== $modelAlias) {
128
            $query->setModelAlias($modelAlias);
129
        }
130
        if ($criteria instanceof Criteria) {
131
            $query->mergeWith($criteria);
132
        }
133
134
        return $query;
135
    }
136
137
    /**
138
     * Find object by primary key.
139
     * Propel uses the instance pool to skip the database if the object exists.
140
     * Go fast if the query is untouched.
141
     *
142
     * <code>
143
     * $obj  = $c->findPk(12, $con);
144
     * </code>
145
     *
146
     * @param mixed $key Primary key to use for the query
147
     * @param ConnectionInterface $con an optional connection object
148
     *
149
     * @return ChildConnection|array|mixed the result, formatted by the current formatter
150
     */
151 View Code Duplication
    public function findPk($key, ConnectionInterface $con = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
152
    {
153
        if ($key === null) {
154
            return null;
155
        }
156
        if ((null !== ($obj = ConnectionTableMap::getInstanceFromPool(null === $key || is_scalar($key) || is_callable([$key, '__toString']) ? (string) $key : $key))) && !$this->formatter) {
157
            // the object is already in the instance pool
158
            return $obj;
159
        }
160
        if ($con === null) {
161
            $con = Propel::getServiceContainer()->getReadConnection(ConnectionTableMap::DATABASE_NAME);
162
        }
163
        $this->basePreSelect($con);
164
        if ($this->formatter || $this->modelAlias || $this->with || $this->select
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->modelAlias of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
Bug Best Practice introduced by
The expression $this->with of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
165
         || $this->selectColumns || $this->asColumns || $this->selectModifiers
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->selectColumns of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
Bug Best Practice introduced by
The expression $this->asColumns of type string[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
Bug Best Practice introduced by
The expression $this->selectModifiers of type string[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
166
         || $this->map || $this->having || $this->joins) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->map of type Propel\Runtime\ActiveQue...ion\AbstractCriterion[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
Bug Best Practice introduced by
The expression $this->joins of type Propel\Runtime\ActiveQuery\Join[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
167
            return $this->findPkComplex($key, $con);
168
        } else {
169
            return $this->findPkSimple($key, $con);
170
        }
171
    }
172
173
    /**
174
     * Find object by primary key using raw SQL to go fast.
175
     * Bypass doSelect() and the object formatter by using generated code.
176
     *
177
     * @param     mixed $key Primary key to use for the query
178
     * @param     ConnectionInterface $con A connection object
179
     *
180
     * @throws \Propel\Runtime\Exception\PropelException
181
     *
182
     * @return ChildConnection A model object, or null if the key is not found
183
     */
184 View Code Duplication
    protected function findPkSimple($key, ConnectionInterface $con)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
185
    {
186
        $sql = 'SELECT id, instance_name, user_id, peer, started, type FROM connection WHERE id = :p0';
187
        try {
188
            $stmt = $con->prepare($sql);
189
            $stmt->bindValue(':p0', $key, PDO::PARAM_INT);
190
            $stmt->execute();
191
        } catch (Exception $e) {
192
            Propel::log($e->getMessage(), Propel::LOG_ERR);
193
            throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e);
194
        }
195
        $obj = null;
196
        if ($row = $stmt->fetch(\PDO::FETCH_NUM)) {
197
            /** @var ChildConnection $obj */
198
            $obj = new ChildConnection();
199
            $obj->hydrate($row);
200
            ConnectionTableMap::addInstanceToPool($obj, null === $key || is_scalar($key) || is_callable([$key, '__toString']) ? (string) $key : $key);
201
        }
202
        $stmt->closeCursor();
203
204
        return $obj;
205
    }
206
207
    /**
208
     * Find object by primary key.
209
     *
210
     * @param     mixed $key Primary key to use for the query
211
     * @param     ConnectionInterface $con A connection object
212
     *
213
     * @return ChildConnection|array|mixed the result, formatted by the current formatter
214
     */
215 View Code Duplication
    protected function findPkComplex($key, ConnectionInterface $con)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
216
    {
217
        // As the query uses a PK condition, no limit(1) is necessary.
218
        $criteria = $this->isKeepQuery() ? clone $this : $this;
219
        $dataFetcher = $criteria
220
            ->filterByPrimaryKey($key)
221
            ->doSelect($con);
222
223
        return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher);
224
    }
225
226
    /**
227
     * Find objects by primary key
228
     * <code>
229
     * $objs = $c->findPks(array(12, 56, 832), $con);
230
     * </code>
231
     * @param     array $keys Primary keys to use for the query
232
     * @param     ConnectionInterface $con an optional connection object
233
     *
234
     * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter
235
     */
236 View Code Duplication
    public function findPks($keys, ConnectionInterface $con = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
237
    {
238
        if (null === $con) {
239
            $con = Propel::getServiceContainer()->getReadConnection($this->getDbName());
240
        }
241
        $this->basePreSelect($con);
242
        $criteria = $this->isKeepQuery() ? clone $this : $this;
243
        $dataFetcher = $criteria
244
            ->filterByPrimaryKeys($keys)
245
            ->doSelect($con);
246
247
        return $criteria->getFormatter()->init($criteria)->format($dataFetcher);
248
    }
249
250
    /**
251
     * Filter the query by primary key
252
     *
253
     * @param     mixed $key Primary key to use for the query
254
     *
255
     * @return $this|ChildConnectionQuery The current query, for fluid interface
256
     */
257
    public function filterByPrimaryKey($key)
258
    {
259
260
        return $this->addUsingAlias(ConnectionTableMap::COL_ID, $key, Criteria::EQUAL);
261
    }
262
263
    /**
264
     * Filter the query by a list of primary keys
265
     *
266
     * @param     array $keys The list of primary key to use for the query
267
     *
268
     * @return $this|ChildConnectionQuery The current query, for fluid interface
269
     */
270
    public function filterByPrimaryKeys($keys)
271
    {
272
273
        return $this->addUsingAlias(ConnectionTableMap::COL_ID, $keys, Criteria::IN);
274
    }
275
276
    /**
277
     * Filter the query on the id column
278
     *
279
     * Example usage:
280
     * <code>
281
     * $query->filterById(1234); // WHERE id = 1234
282
     * $query->filterById(array(12, 34)); // WHERE id IN (12, 34)
283
     * $query->filterById(array('min' => 12)); // WHERE id > 12
284
     * </code>
285
     *
286
     * @param     mixed $id The value to use as filter.
287
     *              Use scalar values for equality.
288
     *              Use array values for in_array() equivalent.
289
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
290
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
291
     *
292
     * @return $this|ChildConnectionQuery The current query, for fluid interface
293
     */
294 View Code Duplication
    public function filterById($id = null, $comparison = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
295
    {
296
        if (is_array($id)) {
297
            $useMinMax = false;
298
            if (isset($id['min'])) {
299
                $this->addUsingAlias(ConnectionTableMap::COL_ID, $id['min'], Criteria::GREATER_EQUAL);
300
                $useMinMax = true;
301
            }
302
            if (isset($id['max'])) {
303
                $this->addUsingAlias(ConnectionTableMap::COL_ID, $id['max'], Criteria::LESS_EQUAL);
304
                $useMinMax = true;
305
            }
306
            if ($useMinMax) {
307
                return $this;
308
            }
309
            if (null === $comparison) {
310
                $comparison = Criteria::IN;
311
            }
312
        }
313
314
        return $this->addUsingAlias(ConnectionTableMap::COL_ID, $id, $comparison);
315
    }
316
317
    /**
318
     * Filter the query on the instance_name column
319
     *
320
     * Example usage:
321
     * <code>
322
     * $query->filterByInstanceName('fooValue');   // WHERE instance_name = 'fooValue'
323
     * $query->filterByInstanceName('%fooValue%'); // WHERE instance_name LIKE '%fooValue%'
324
     * </code>
325
     *
326
     * @param     string $instanceName The value to use as filter.
327
     *              Accepts wildcards (* and % trigger a LIKE)
328
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
329
     *
330
     * @return $this|ChildConnectionQuery The current query, for fluid interface
331
     */
332 View Code Duplication
    public function filterByInstanceName($instanceName = null, $comparison = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
333
    {
334
        if (null === $comparison) {
335
            if (is_array($instanceName)) {
336
                $comparison = Criteria::IN;
337
            } elseif (preg_match('/[\%\*]/', $instanceName)) {
338
                $instanceName = str_replace('*', '%', $instanceName);
339
                $comparison = Criteria::LIKE;
340
            }
341
        }
342
343
        return $this->addUsingAlias(ConnectionTableMap::COL_INSTANCE_NAME, $instanceName, $comparison);
344
    }
345
346
    /**
347
     * Filter the query on the user_id column
348
     *
349
     * Example usage:
350
     * <code>
351
     * $query->filterByUserId(1234); // WHERE user_id = 1234
352
     * $query->filterByUserId(array(12, 34)); // WHERE user_id IN (12, 34)
353
     * $query->filterByUserId(array('min' => 12)); // WHERE user_id > 12
354
     * </code>
355
     *
356
     * @see       filterByUser()
357
     *
358
     * @param     mixed $userId The value to use as filter.
359
     *              Use scalar values for equality.
360
     *              Use array values for in_array() equivalent.
361
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
362
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
363
     *
364
     * @return $this|ChildConnectionQuery The current query, for fluid interface
365
     */
366 View Code Duplication
    public function filterByUserId($userId = null, $comparison = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
367
    {
368
        if (is_array($userId)) {
369
            $useMinMax = false;
370
            if (isset($userId['min'])) {
371
                $this->addUsingAlias(ConnectionTableMap::COL_USER_ID, $userId['min'], Criteria::GREATER_EQUAL);
372
                $useMinMax = true;
373
            }
374
            if (isset($userId['max'])) {
375
                $this->addUsingAlias(ConnectionTableMap::COL_USER_ID, $userId['max'], Criteria::LESS_EQUAL);
376
                $useMinMax = true;
377
            }
378
            if ($useMinMax) {
379
                return $this;
380
            }
381
            if (null === $comparison) {
382
                $comparison = Criteria::IN;
383
            }
384
        }
385
386
        return $this->addUsingAlias(ConnectionTableMap::COL_USER_ID, $userId, $comparison);
387
    }
388
389
    /**
390
     * Filter the query on the peer column
391
     *
392
     * Example usage:
393
     * <code>
394
     * $query->filterByPeer('fooValue');   // WHERE peer = 'fooValue'
395
     * $query->filterByPeer('%fooValue%'); // WHERE peer LIKE '%fooValue%'
396
     * </code>
397
     *
398
     * @param     string $peer The value to use as filter.
399
     *              Accepts wildcards (* and % trigger a LIKE)
400
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
401
     *
402
     * @return $this|ChildConnectionQuery The current query, for fluid interface
403
     */
404 View Code Duplication
    public function filterByPeer($peer = null, $comparison = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
405
    {
406
        if (null === $comparison) {
407
            if (is_array($peer)) {
408
                $comparison = Criteria::IN;
409
            } elseif (preg_match('/[\%\*]/', $peer)) {
410
                $peer = str_replace('*', '%', $peer);
411
                $comparison = Criteria::LIKE;
412
            }
413
        }
414
415
        return $this->addUsingAlias(ConnectionTableMap::COL_PEER, $peer, $comparison);
416
    }
417
418
    /**
419
     * Filter the query on the started column
420
     *
421
     * Example usage:
422
     * <code>
423
     * $query->filterByStarted('2011-03-14'); // WHERE started = '2011-03-14'
424
     * $query->filterByStarted('now'); // WHERE started = '2011-03-14'
425
     * $query->filterByStarted(array('max' => 'yesterday')); // WHERE started > '2011-03-13'
426
     * </code>
427
     *
428
     * @param     mixed $started The value to use as filter.
429
     *              Values can be integers (unix timestamps), DateTime objects, or strings.
430
     *              Empty strings are treated as NULL.
431
     *              Use scalar values for equality.
432
     *              Use array values for in_array() equivalent.
433
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
434
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
435
     *
436
     * @return $this|ChildConnectionQuery The current query, for fluid interface
437
     */
438 View Code Duplication
    public function filterByStarted($started = null, $comparison = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
439
    {
440
        if (is_array($started)) {
441
            $useMinMax = false;
442
            if (isset($started['min'])) {
443
                $this->addUsingAlias(ConnectionTableMap::COL_STARTED, $started['min'], Criteria::GREATER_EQUAL);
444
                $useMinMax = true;
445
            }
446
            if (isset($started['max'])) {
447
                $this->addUsingAlias(ConnectionTableMap::COL_STARTED, $started['max'], Criteria::LESS_EQUAL);
448
                $useMinMax = true;
449
            }
450
            if ($useMinMax) {
451
                return $this;
452
            }
453
            if (null === $comparison) {
454
                $comparison = Criteria::IN;
455
            }
456
        }
457
458
        return $this->addUsingAlias(ConnectionTableMap::COL_STARTED, $started, $comparison);
459
    }
460
461
    /**
462
     * Filter the query on the type column
463
     *
464
     * Example usage:
465
     * <code>
466
     * $query->filterByType('fooValue');   // WHERE type = 'fooValue'
467
     * $query->filterByType('%fooValue%'); // WHERE type LIKE '%fooValue%'
468
     * </code>
469
     *
470
     * @param     string $type The value to use as filter.
471
     *              Accepts wildcards (* and % trigger a LIKE)
472
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
473
     *
474
     * @return $this|ChildConnectionQuery The current query, for fluid interface
475
     */
476 View Code Duplication
    public function filterByType($type = null, $comparison = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
477
    {
478
        if (null === $comparison) {
479
            if (is_array($type)) {
480
                $comparison = Criteria::IN;
481
            } elseif (preg_match('/[\%\*]/', $type)) {
482
                $type = str_replace('*', '%', $type);
483
                $comparison = Criteria::LIKE;
484
            }
485
        }
486
487
        return $this->addUsingAlias(ConnectionTableMap::COL_TYPE, $type, $comparison);
488
    }
489
490
    /**
491
     * Filter the query by a related \Jalle19\StatusManager\Database\Instance object
492
     *
493
     * @param \Jalle19\StatusManager\Database\Instance|ObjectCollection $instance The related object(s) to use as filter
494
     * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
495
     *
496
     * @throws \Propel\Runtime\Exception\PropelException
497
     *
498
     * @return ChildConnectionQuery The current query, for fluid interface
499
     */
500 View Code Duplication
    public function filterByInstance($instance, $comparison = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
501
    {
502
        if ($instance instanceof \Jalle19\StatusManager\Database\Instance) {
503
            return $this
504
                ->addUsingAlias(ConnectionTableMap::COL_INSTANCE_NAME, $instance->getName(), $comparison);
505
        } elseif ($instance instanceof ObjectCollection) {
506
            if (null === $comparison) {
507
                $comparison = Criteria::IN;
508
            }
509
510
            return $this
511
                ->addUsingAlias(ConnectionTableMap::COL_INSTANCE_NAME, $instance->toKeyValue('PrimaryKey', 'Name'), $comparison);
512
        } else {
513
            throw new PropelException('filterByInstance() only accepts arguments of type \Jalle19\StatusManager\Database\Instance or Collection');
514
        }
515
    }
516
517
    /**
518
     * Adds a JOIN clause to the query using the Instance relation
519
     *
520
     * @param     string $relationAlias optional alias for the relation
521
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
522
     *
523
     * @return $this|ChildConnectionQuery The current query, for fluid interface
524
     */
525 View Code Duplication
    public function joinInstance($relationAlias = null, $joinType = Criteria::INNER_JOIN)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
526
    {
527
        $tableMap = $this->getTableMap();
528
        $relationMap = $tableMap->getRelation('Instance');
529
530
        // create a ModelJoin object for this join
531
        $join = new ModelJoin();
532
        $join->setJoinType($joinType);
533
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
534
        if ($previousJoin = $this->getPreviousJoin()) {
535
            $join->setPreviousJoin($previousJoin);
0 ignored issues
show
Compatibility introduced by
$previousJoin of type object<Propel\Runtime\ActiveQuery\Join> is not a sub-type of object<Propel\Runtime\ActiveQuery\ModelJoin>. It seems like you assume a child class of the class Propel\Runtime\ActiveQuery\Join to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
536
        }
537
538
        // add the ModelJoin to the current object
539
        if ($relationAlias) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $relationAlias of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
540
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
541
            $this->addJoinObject($join, $relationAlias);
542
        } else {
543
            $this->addJoinObject($join, 'Instance');
544
        }
545
546
        return $this;
547
    }
548
549
    /**
550
     * Use the Instance relation Instance object
551
     *
552
     * @see useQuery()
553
     *
554
     * @param     string $relationAlias optional alias for the relation,
555
     *                                   to be used as main alias in the secondary query
556
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
557
     *
558
     * @return \Jalle19\StatusManager\Database\InstanceQuery A secondary query class using the current class as primary query
559
     */
560
    public function useInstanceQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
561
    {
562
        return $this
563
            ->joinInstance($relationAlias, $joinType)
564
            ->useQuery($relationAlias ? $relationAlias : 'Instance', '\Jalle19\StatusManager\Database\InstanceQuery');
565
    }
566
567
    /**
568
     * Filter the query by a related \Jalle19\StatusManager\Database\User object
569
     *
570
     * @param \Jalle19\StatusManager\Database\User|ObjectCollection $user The related object(s) to use as filter
571
     * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
572
     *
573
     * @throws \Propel\Runtime\Exception\PropelException
574
     *
575
     * @return ChildConnectionQuery The current query, for fluid interface
576
     */
577 View Code Duplication
    public function filterByUser($user, $comparison = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
578
    {
579
        if ($user instanceof \Jalle19\StatusManager\Database\User) {
580
            return $this
581
                ->addUsingAlias(ConnectionTableMap::COL_USER_ID, $user->getId(), $comparison);
582
        } elseif ($user instanceof ObjectCollection) {
583
            if (null === $comparison) {
584
                $comparison = Criteria::IN;
585
            }
586
587
            return $this
588
                ->addUsingAlias(ConnectionTableMap::COL_USER_ID, $user->toKeyValue('PrimaryKey', 'Id'), $comparison);
589
        } else {
590
            throw new PropelException('filterByUser() only accepts arguments of type \Jalle19\StatusManager\Database\User or Collection');
591
        }
592
    }
593
594
    /**
595
     * Adds a JOIN clause to the query using the User relation
596
     *
597
     * @param     string $relationAlias optional alias for the relation
598
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
599
     *
600
     * @return $this|ChildConnectionQuery The current query, for fluid interface
601
     */
602 View Code Duplication
    public function joinUser($relationAlias = null, $joinType = Criteria::LEFT_JOIN)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
603
    {
604
        $tableMap = $this->getTableMap();
605
        $relationMap = $tableMap->getRelation('User');
606
607
        // create a ModelJoin object for this join
608
        $join = new ModelJoin();
609
        $join->setJoinType($joinType);
610
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
611
        if ($previousJoin = $this->getPreviousJoin()) {
612
            $join->setPreviousJoin($previousJoin);
0 ignored issues
show
Compatibility introduced by
$previousJoin of type object<Propel\Runtime\ActiveQuery\Join> is not a sub-type of object<Propel\Runtime\ActiveQuery\ModelJoin>. It seems like you assume a child class of the class Propel\Runtime\ActiveQuery\Join to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
613
        }
614
615
        // add the ModelJoin to the current object
616
        if ($relationAlias) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $relationAlias of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
617
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
618
            $this->addJoinObject($join, $relationAlias);
619
        } else {
620
            $this->addJoinObject($join, 'User');
621
        }
622
623
        return $this;
624
    }
625
626
    /**
627
     * Use the User relation User object
628
     *
629
     * @see useQuery()
630
     *
631
     * @param     string $relationAlias optional alias for the relation,
632
     *                                   to be used as main alias in the secondary query
633
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
634
     *
635
     * @return \Jalle19\StatusManager\Database\UserQuery A secondary query class using the current class as primary query
636
     */
637
    public function useUserQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN)
638
    {
639
        return $this
640
            ->joinUser($relationAlias, $joinType)
641
            ->useQuery($relationAlias ? $relationAlias : 'User', '\Jalle19\StatusManager\Database\UserQuery');
642
    }
643
644
    /**
645
     * Exclude object from result
646
     *
647
     * @param   ChildConnection $connection Object to remove from the list of results
648
     *
649
     * @return $this|ChildConnectionQuery The current query, for fluid interface
650
     */
651
    public function prune($connection = null)
652
    {
653
        if ($connection) {
654
            $this->addUsingAlias(ConnectionTableMap::COL_ID, $connection->getId(), Criteria::NOT_EQUAL);
655
        }
656
657
        return $this;
658
    }
659
660
    /**
661
     * Deletes all rows from the connection table.
662
     *
663
     * @param ConnectionInterface $con the connection to use
664
     * @return int The number of affected rows (if supported by underlying database driver).
665
     */
666 View Code Duplication
    public function doDeleteAll(ConnectionInterface $con = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
667
    {
668
        if (null === $con) {
669
            $con = Propel::getServiceContainer()->getWriteConnection(ConnectionTableMap::DATABASE_NAME);
670
        }
671
672
        // use transaction because $criteria could contain info
673
        // for more than one table or we could emulating ON DELETE CASCADE, etc.
674
        return $con->transaction(function () use ($con) {
675
            $affectedRows = 0; // initialize var to track total num of affected rows
676
            $affectedRows += parent::doDeleteAll($con);
677
            // Because this db requires some delete cascade/set null emulation, we have to
678
            // clear the cached instance *after* the emulation has happened (since
679
            // instances get re-added by the select statement contained therein).
680
            ConnectionTableMap::clearInstancePool();
681
            ConnectionTableMap::clearRelatedInstancePool();
682
683
            return $affectedRows;
684
        });
685
    }
686
687
    /**
688
     * Performs a DELETE on the database based on the current ModelCriteria
689
     *
690
     * @param ConnectionInterface $con the connection to use
691
     * @return int             The number of affected rows (if supported by underlying database driver).  This includes CASCADE-related rows
692
     *                         if supported by native driver or if emulated using Propel.
693
     * @throws PropelException Any exceptions caught during processing will be
694
     *                         rethrown wrapped into a PropelException.
695
     */
696 View Code Duplication
    public function delete(ConnectionInterface $con = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
697
    {
698
        if (null === $con) {
699
            $con = Propel::getServiceContainer()->getWriteConnection(ConnectionTableMap::DATABASE_NAME);
700
        }
701
702
        $criteria = $this;
703
704
        // Set the correct dbName
705
        $criteria->setDbName(ConnectionTableMap::DATABASE_NAME);
706
707
        // use transaction because $criteria could contain info
708
        // for more than one table or we could emulating ON DELETE CASCADE, etc.
709
        return $con->transaction(function () use ($con, $criteria) {
710
            $affectedRows = 0; // initialize var to track total num of affected rows
711
712
            ConnectionTableMap::removeInstanceFromPool($criteria);
713
714
            $affectedRows += ModelCriteria::delete($con);
715
            ConnectionTableMap::clearRelatedInstancePool();
716
717
            return $affectedRows;
718
        });
719
    }
720
721
} // ConnectionQuery
722