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

ChannelQuery   F

Complexity

Total Complexity 75

Size/Duplication

Total Lines 506
Duplicated Lines 49.21 %

Coupling/Cohesion

Components 2
Dependencies 17

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 75
c 1
b 0
f 0
lcom 2
cbo 17
dl 249
loc 506
rs 2.3076

20 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
A filterByName() 13 13 4
A filterByInstance() 16 16 4
B joinInstance() 23 23 4
A useInstanceQuery() 0 6 2
A filterBySubscription() 14 14 3
B joinSubscription() 23 23 4
A useSubscriptionQuery() 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 ChannelQuery 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 ChannelQuery, 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\Channel as ChildChannel;
8
use Jalle19\StatusManager\Database\ChannelQuery as ChildChannelQuery;
9
use Jalle19\StatusManager\Database\Map\ChannelTableMap;
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 'channel' table.
20
 *
21
 *
22
 *
23
 * @method     ChildChannelQuery orderById($order = Criteria::ASC) Order by the id column
24
 * @method     ChildChannelQuery orderByInstanceName($order = Criteria::ASC) Order by the instance_name column
25
 * @method     ChildChannelQuery orderByName($order = Criteria::ASC) Order by the name column
26
 *
27
 * @method     ChildChannelQuery groupById() Group by the id column
28
 * @method     ChildChannelQuery groupByInstanceName() Group by the instance_name column
29
 * @method     ChildChannelQuery groupByName() Group by the name column
30
 *
31
 * @method     ChildChannelQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
32
 * @method     ChildChannelQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
33
 * @method     ChildChannelQuery innerJoin($relation) Adds a INNER JOIN clause to the query
34
 *
35
 * @method     ChildChannelQuery leftJoinWith($relation) Adds a LEFT JOIN clause and with to the query
36
 * @method     ChildChannelQuery rightJoinWith($relation) Adds a RIGHT JOIN clause and with to the query
37
 * @method     ChildChannelQuery innerJoinWith($relation) Adds a INNER JOIN clause and with to the query
38
 *
39
 * @method     ChildChannelQuery leftJoinInstance($relationAlias = null) Adds a LEFT JOIN clause to the query using the Instance relation
40
 * @method     ChildChannelQuery rightJoinInstance($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Instance relation
41
 * @method     ChildChannelQuery innerJoinInstance($relationAlias = null) Adds a INNER JOIN clause to the query using the Instance relation
42
 *
43
 * @method     ChildChannelQuery joinWithInstance($joinType = Criteria::INNER_JOIN) Adds a join clause and with to the query using the Instance relation
44
 *
45
 * @method     ChildChannelQuery leftJoinWithInstance() Adds a LEFT JOIN clause and with to the query using the Instance relation
46
 * @method     ChildChannelQuery rightJoinWithInstance() Adds a RIGHT JOIN clause and with to the query using the Instance relation
47
 * @method     ChildChannelQuery innerJoinWithInstance() Adds a INNER JOIN clause and with to the query using the Instance relation
48
 *
49
 * @method     ChildChannelQuery leftJoinSubscription($relationAlias = null) Adds a LEFT JOIN clause to the query using the Subscription relation
50
 * @method     ChildChannelQuery rightJoinSubscription($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Subscription relation
51
 * @method     ChildChannelQuery innerJoinSubscription($relationAlias = null) Adds a INNER JOIN clause to the query using the Subscription relation
52
 *
53
 * @method     ChildChannelQuery joinWithSubscription($joinType = Criteria::INNER_JOIN) Adds a join clause and with to the query using the Subscription relation
54
 *
55
 * @method     ChildChannelQuery leftJoinWithSubscription() Adds a LEFT JOIN clause and with to the query using the Subscription relation
56
 * @method     ChildChannelQuery rightJoinWithSubscription() Adds a RIGHT JOIN clause and with to the query using the Subscription relation
57
 * @method     ChildChannelQuery innerJoinWithSubscription() Adds a INNER JOIN clause and with to the query using the Subscription relation
58
 *
59
 * @method     \Jalle19\StatusManager\Database\InstanceQuery|\Jalle19\StatusManager\Database\SubscriptionQuery endUse() Finalizes a secondary criteria and merges it with its primary Criteria
60
 *
61
 * @method     ChildChannel findOne(ConnectionInterface $con = null) Return the first ChildChannel matching the query
62
 * @method     ChildChannel findOneOrCreate(ConnectionInterface $con = null) Return the first ChildChannel matching the query, or a new ChildChannel object populated from the query conditions when no match is found
63
 *
64
 * @method     ChildChannel findOneById(int $id) Return the first ChildChannel filtered by the id column
65
 * @method     ChildChannel findOneByInstanceName(string $instance_name) Return the first ChildChannel filtered by the instance_name column
66
 * @method     ChildChannel findOneByName(string $name) Return the first ChildChannel filtered by the name column *
67
68
 * @method     ChildChannel requirePk($key, ConnectionInterface $con = null) Return the ChildChannel by primary key and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
69
 * @method     ChildChannel requireOne(ConnectionInterface $con = null) Return the first ChildChannel matching the query and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
70
 *
71
 * @method     ChildChannel requireOneById(int $id) Return the first ChildChannel filtered by the id column and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
72
 * @method     ChildChannel requireOneByInstanceName(string $instance_name) Return the first ChildChannel filtered by the instance_name column and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
73
 * @method     ChildChannel requireOneByName(string $name) Return the first ChildChannel filtered by the name column and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
74
 *
75
 * @method     ChildChannel[]|ObjectCollection find(ConnectionInterface $con = null) Return ChildChannel objects based on current ModelCriteria
76
 * @method     ChildChannel[]|ObjectCollection findById(int $id) Return ChildChannel objects filtered by the id column
77
 * @method     ChildChannel[]|ObjectCollection findByInstanceName(string $instance_name) Return ChildChannel objects filtered by the instance_name column
78
 * @method     ChildChannel[]|ObjectCollection findByName(string $name) Return ChildChannel objects filtered by the name column
79
 * @method     ChildChannel[]|\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
80
 *
81
 */
82
abstract class ChannelQuery extends ModelCriteria
83
{
84
    protected $entityNotFoundExceptionClass = '\\Propel\\Runtime\\Exception\\EntityNotFoundException';
85
86
    /**
87
     * Initializes internal state of \Jalle19\StatusManager\Database\Base\ChannelQuery object.
88
     *
89
     * @param     string $dbName The database name
90
     * @param     string $modelName The phpName of a model, e.g. 'Book'
91
     * @param     string $modelAlias The alias for the model in this query, e.g. 'b'
92
     */
93
    public function __construct($dbName = 'tvheadend_status_manager', $modelName = '\\Jalle19\\StatusManager\\Database\\Channel', $modelAlias = null)
94
    {
95
        parent::__construct($dbName, $modelName, $modelAlias);
96
    }
97
98
    /**
99
     * Returns a new ChildChannelQuery object.
100
     *
101
     * @param     string $modelAlias The alias of a model in the query
102
     * @param     Criteria $criteria Optional Criteria to build the query from
103
     *
104
     * @return ChildChannelQuery
105
     */
106 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...
107
    {
108
        if ($criteria instanceof ChildChannelQuery) {
109
            return $criteria;
110
        }
111
        $query = new ChildChannelQuery();
112
        if (null !== $modelAlias) {
113
            $query->setModelAlias($modelAlias);
114
        }
115
        if ($criteria instanceof Criteria) {
116
            $query->mergeWith($criteria);
117
        }
118
119
        return $query;
120
    }
121
122
    /**
123
     * Find object by primary key.
124
     * Propel uses the instance pool to skip the database if the object exists.
125
     * Go fast if the query is untouched.
126
     *
127
     * <code>
128
     * $obj  = $c->findPk(12, $con);
129
     * </code>
130
     *
131
     * @param mixed $key Primary key to use for the query
132
     * @param ConnectionInterface $con an optional connection object
133
     *
134
     * @return ChildChannel|array|mixed the result, formatted by the current formatter
135
     */
136 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...
137
    {
138
        if ($key === null) {
139
            return null;
140
        }
141
        if ((null !== ($obj = ChannelTableMap::getInstanceFromPool(null === $key || is_scalar($key) || is_callable([$key, '__toString']) ? (string) $key : $key))) && !$this->formatter) {
142
            // the object is already in the instance pool
143
            return $obj;
144
        }
145
        if ($con === null) {
146
            $con = Propel::getServiceContainer()->getReadConnection(ChannelTableMap::DATABASE_NAME);
147
        }
148
        $this->basePreSelect($con);
149
        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...
150
         || $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...
151
         || $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...
152
            return $this->findPkComplex($key, $con);
153
        } else {
154
            return $this->findPkSimple($key, $con);
155
        }
156
    }
157
158
    /**
159
     * Find object by primary key using raw SQL to go fast.
160
     * Bypass doSelect() and the object formatter by using generated code.
161
     *
162
     * @param     mixed $key Primary key to use for the query
163
     * @param     ConnectionInterface $con A connection object
164
     *
165
     * @throws \Propel\Runtime\Exception\PropelException
166
     *
167
     * @return ChildChannel A model object, or null if the key is not found
168
     */
169 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...
170
    {
171
        $sql = 'SELECT id, instance_name, name FROM channel WHERE id = :p0';
172
        try {
173
            $stmt = $con->prepare($sql);
174
            $stmt->bindValue(':p0', $key, PDO::PARAM_INT);
175
            $stmt->execute();
176
        } catch (Exception $e) {
177
            Propel::log($e->getMessage(), Propel::LOG_ERR);
178
            throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e);
179
        }
180
        $obj = null;
181
        if ($row = $stmt->fetch(\PDO::FETCH_NUM)) {
182
            /** @var ChildChannel $obj */
183
            $obj = new ChildChannel();
184
            $obj->hydrate($row);
185
            ChannelTableMap::addInstanceToPool($obj, null === $key || is_scalar($key) || is_callable([$key, '__toString']) ? (string) $key : $key);
186
        }
187
        $stmt->closeCursor();
188
189
        return $obj;
190
    }
191
192
    /**
193
     * Find object by primary key.
194
     *
195
     * @param     mixed $key Primary key to use for the query
196
     * @param     ConnectionInterface $con A connection object
197
     *
198
     * @return ChildChannel|array|mixed the result, formatted by the current formatter
199
     */
200 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...
201
    {
202
        // As the query uses a PK condition, no limit(1) is necessary.
203
        $criteria = $this->isKeepQuery() ? clone $this : $this;
204
        $dataFetcher = $criteria
205
            ->filterByPrimaryKey($key)
206
            ->doSelect($con);
207
208
        return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher);
209
    }
210
211
    /**
212
     * Find objects by primary key
213
     * <code>
214
     * $objs = $c->findPks(array(12, 56, 832), $con);
215
     * </code>
216
     * @param     array $keys Primary keys to use for the query
217
     * @param     ConnectionInterface $con an optional connection object
218
     *
219
     * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter
220
     */
221 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...
222
    {
223
        if (null === $con) {
224
            $con = Propel::getServiceContainer()->getReadConnection($this->getDbName());
225
        }
226
        $this->basePreSelect($con);
227
        $criteria = $this->isKeepQuery() ? clone $this : $this;
228
        $dataFetcher = $criteria
229
            ->filterByPrimaryKeys($keys)
230
            ->doSelect($con);
231
232
        return $criteria->getFormatter()->init($criteria)->format($dataFetcher);
233
    }
234
235
    /**
236
     * Filter the query by primary key
237
     *
238
     * @param     mixed $key Primary key to use for the query
239
     *
240
     * @return $this|ChildChannelQuery The current query, for fluid interface
241
     */
242
    public function filterByPrimaryKey($key)
243
    {
244
245
        return $this->addUsingAlias(ChannelTableMap::COL_ID, $key, Criteria::EQUAL);
246
    }
247
248
    /**
249
     * Filter the query by a list of primary keys
250
     *
251
     * @param     array $keys The list of primary key to use for the query
252
     *
253
     * @return $this|ChildChannelQuery The current query, for fluid interface
254
     */
255
    public function filterByPrimaryKeys($keys)
256
    {
257
258
        return $this->addUsingAlias(ChannelTableMap::COL_ID, $keys, Criteria::IN);
259
    }
260
261
    /**
262
     * Filter the query on the id column
263
     *
264
     * Example usage:
265
     * <code>
266
     * $query->filterById(1234); // WHERE id = 1234
267
     * $query->filterById(array(12, 34)); // WHERE id IN (12, 34)
268
     * $query->filterById(array('min' => 12)); // WHERE id > 12
269
     * </code>
270
     *
271
     * @param     mixed $id The value to use as filter.
272
     *              Use scalar values for equality.
273
     *              Use array values for in_array() equivalent.
274
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
275
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
276
     *
277
     * @return $this|ChildChannelQuery The current query, for fluid interface
278
     */
279 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...
280
    {
281
        if (is_array($id)) {
282
            $useMinMax = false;
283
            if (isset($id['min'])) {
284
                $this->addUsingAlias(ChannelTableMap::COL_ID, $id['min'], Criteria::GREATER_EQUAL);
285
                $useMinMax = true;
286
            }
287
            if (isset($id['max'])) {
288
                $this->addUsingAlias(ChannelTableMap::COL_ID, $id['max'], Criteria::LESS_EQUAL);
289
                $useMinMax = true;
290
            }
291
            if ($useMinMax) {
292
                return $this;
293
            }
294
            if (null === $comparison) {
295
                $comparison = Criteria::IN;
296
            }
297
        }
298
299
        return $this->addUsingAlias(ChannelTableMap::COL_ID, $id, $comparison);
300
    }
301
302
    /**
303
     * Filter the query on the instance_name column
304
     *
305
     * Example usage:
306
     * <code>
307
     * $query->filterByInstanceName('fooValue');   // WHERE instance_name = 'fooValue'
308
     * $query->filterByInstanceName('%fooValue%'); // WHERE instance_name LIKE '%fooValue%'
309
     * </code>
310
     *
311
     * @param     string $instanceName The value to use as filter.
312
     *              Accepts wildcards (* and % trigger a LIKE)
313
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
314
     *
315
     * @return $this|ChildChannelQuery The current query, for fluid interface
316
     */
317 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...
318
    {
319
        if (null === $comparison) {
320
            if (is_array($instanceName)) {
321
                $comparison = Criteria::IN;
322
            } elseif (preg_match('/[\%\*]/', $instanceName)) {
323
                $instanceName = str_replace('*', '%', $instanceName);
324
                $comparison = Criteria::LIKE;
325
            }
326
        }
327
328
        return $this->addUsingAlias(ChannelTableMap::COL_INSTANCE_NAME, $instanceName, $comparison);
329
    }
330
331
    /**
332
     * Filter the query on the name column
333
     *
334
     * Example usage:
335
     * <code>
336
     * $query->filterByName('fooValue');   // WHERE name = 'fooValue'
337
     * $query->filterByName('%fooValue%'); // WHERE name LIKE '%fooValue%'
338
     * </code>
339
     *
340
     * @param     string $name The value to use as filter.
341
     *              Accepts wildcards (* and % trigger a LIKE)
342
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
343
     *
344
     * @return $this|ChildChannelQuery The current query, for fluid interface
345
     */
346 View Code Duplication
    public function filterByName($name = 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...
347
    {
348
        if (null === $comparison) {
349
            if (is_array($name)) {
350
                $comparison = Criteria::IN;
351
            } elseif (preg_match('/[\%\*]/', $name)) {
352
                $name = str_replace('*', '%', $name);
353
                $comparison = Criteria::LIKE;
354
            }
355
        }
356
357
        return $this->addUsingAlias(ChannelTableMap::COL_NAME, $name, $comparison);
358
    }
359
360
    /**
361
     * Filter the query by a related \Jalle19\StatusManager\Database\Instance object
362
     *
363
     * @param \Jalle19\StatusManager\Database\Instance|ObjectCollection $instance The related object(s) to use as filter
364
     * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
365
     *
366
     * @throws \Propel\Runtime\Exception\PropelException
367
     *
368
     * @return ChildChannelQuery The current query, for fluid interface
369
     */
370 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...
371
    {
372
        if ($instance instanceof \Jalle19\StatusManager\Database\Instance) {
373
            return $this
374
                ->addUsingAlias(ChannelTableMap::COL_INSTANCE_NAME, $instance->getName(), $comparison);
375
        } elseif ($instance instanceof ObjectCollection) {
376
            if (null === $comparison) {
377
                $comparison = Criteria::IN;
378
            }
379
380
            return $this
381
                ->addUsingAlias(ChannelTableMap::COL_INSTANCE_NAME, $instance->toKeyValue('PrimaryKey', 'Name'), $comparison);
382
        } else {
383
            throw new PropelException('filterByInstance() only accepts arguments of type \Jalle19\StatusManager\Database\Instance or Collection');
384
        }
385
    }
386
387
    /**
388
     * Adds a JOIN clause to the query using the Instance relation
389
     *
390
     * @param     string $relationAlias optional alias for the relation
391
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
392
     *
393
     * @return $this|ChildChannelQuery The current query, for fluid interface
394
     */
395 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...
396
    {
397
        $tableMap = $this->getTableMap();
398
        $relationMap = $tableMap->getRelation('Instance');
399
400
        // create a ModelJoin object for this join
401
        $join = new ModelJoin();
402
        $join->setJoinType($joinType);
403
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
404
        if ($previousJoin = $this->getPreviousJoin()) {
405
            $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...
406
        }
407
408
        // add the ModelJoin to the current object
409
        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...
410
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
411
            $this->addJoinObject($join, $relationAlias);
412
        } else {
413
            $this->addJoinObject($join, 'Instance');
414
        }
415
416
        return $this;
417
    }
418
419
    /**
420
     * Use the Instance relation Instance object
421
     *
422
     * @see useQuery()
423
     *
424
     * @param     string $relationAlias optional alias for the relation,
425
     *                                   to be used as main alias in the secondary query
426
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
427
     *
428
     * @return \Jalle19\StatusManager\Database\InstanceQuery A secondary query class using the current class as primary query
429
     */
430
    public function useInstanceQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
431
    {
432
        return $this
433
            ->joinInstance($relationAlias, $joinType)
434
            ->useQuery($relationAlias ? $relationAlias : 'Instance', '\Jalle19\StatusManager\Database\InstanceQuery');
435
    }
436
437
    /**
438
     * Filter the query by a related \Jalle19\StatusManager\Database\Subscription object
439
     *
440
     * @param \Jalle19\StatusManager\Database\Subscription|ObjectCollection $subscription the related object to use as filter
441
     * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
442
     *
443
     * @return ChildChannelQuery The current query, for fluid interface
444
     */
445 View Code Duplication
    public function filterBySubscription($subscription, $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...
446
    {
447
        if ($subscription instanceof \Jalle19\StatusManager\Database\Subscription) {
448
            return $this
449
                ->addUsingAlias(ChannelTableMap::COL_ID, $subscription->getChannelId(), $comparison);
450
        } elseif ($subscription instanceof ObjectCollection) {
451
            return $this
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->useSubscri...imaryKeys())->endUse(); (Jalle19\StatusManager\Da...r\Database\ChannelQuery) is incompatible with the return type documented by Jalle19\StatusManager\Da...y::filterBySubscription of type Jalle19\StatusManager\Database\ChannelQuery.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

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

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
452
                ->useSubscriptionQuery()
453
                ->filterByPrimaryKeys($subscription->getPrimaryKeys())
454
                ->endUse();
455
        } else {
456
            throw new PropelException('filterBySubscription() only accepts arguments of type \Jalle19\StatusManager\Database\Subscription or Collection');
457
        }
458
    }
459
460
    /**
461
     * Adds a JOIN clause to the query using the Subscription relation
462
     *
463
     * @param     string $relationAlias optional alias for the relation
464
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
465
     *
466
     * @return $this|ChildChannelQuery The current query, for fluid interface
467
     */
468 View Code Duplication
    public function joinSubscription($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...
469
    {
470
        $tableMap = $this->getTableMap();
471
        $relationMap = $tableMap->getRelation('Subscription');
472
473
        // create a ModelJoin object for this join
474
        $join = new ModelJoin();
475
        $join->setJoinType($joinType);
476
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
477
        if ($previousJoin = $this->getPreviousJoin()) {
478
            $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...
479
        }
480
481
        // add the ModelJoin to the current object
482
        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...
483
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
484
            $this->addJoinObject($join, $relationAlias);
485
        } else {
486
            $this->addJoinObject($join, 'Subscription');
487
        }
488
489
        return $this;
490
    }
491
492
    /**
493
     * Use the Subscription relation Subscription object
494
     *
495
     * @see useQuery()
496
     *
497
     * @param     string $relationAlias optional alias for the relation,
498
     *                                   to be used as main alias in the secondary query
499
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
500
     *
501
     * @return \Jalle19\StatusManager\Database\SubscriptionQuery A secondary query class using the current class as primary query
502
     */
503
    public function useSubscriptionQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
504
    {
505
        return $this
506
            ->joinSubscription($relationAlias, $joinType)
507
            ->useQuery($relationAlias ? $relationAlias : 'Subscription', '\Jalle19\StatusManager\Database\SubscriptionQuery');
508
    }
509
510
    /**
511
     * Exclude object from result
512
     *
513
     * @param   ChildChannel $channel Object to remove from the list of results
514
     *
515
     * @return $this|ChildChannelQuery The current query, for fluid interface
516
     */
517
    public function prune($channel = null)
518
    {
519
        if ($channel) {
520
            $this->addUsingAlias(ChannelTableMap::COL_ID, $channel->getId(), Criteria::NOT_EQUAL);
521
        }
522
523
        return $this;
524
    }
525
526
    /**
527
     * Deletes all rows from the channel table.
528
     *
529
     * @param ConnectionInterface $con the connection to use
530
     * @return int The number of affected rows (if supported by underlying database driver).
531
     */
532 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...
533
    {
534
        if (null === $con) {
535
            $con = Propel::getServiceContainer()->getWriteConnection(ChannelTableMap::DATABASE_NAME);
536
        }
537
538
        // use transaction because $criteria could contain info
539
        // for more than one table or we could emulating ON DELETE CASCADE, etc.
540
        return $con->transaction(function () use ($con) {
541
            $affectedRows = 0; // initialize var to track total num of affected rows
542
            $affectedRows += parent::doDeleteAll($con);
543
            // Because this db requires some delete cascade/set null emulation, we have to
544
            // clear the cached instance *after* the emulation has happened (since
545
            // instances get re-added by the select statement contained therein).
546
            ChannelTableMap::clearInstancePool();
547
            ChannelTableMap::clearRelatedInstancePool();
548
549
            return $affectedRows;
550
        });
551
    }
552
553
    /**
554
     * Performs a DELETE on the database based on the current ModelCriteria
555
     *
556
     * @param ConnectionInterface $con the connection to use
557
     * @return int             The number of affected rows (if supported by underlying database driver).  This includes CASCADE-related rows
558
     *                         if supported by native driver or if emulated using Propel.
559
     * @throws PropelException Any exceptions caught during processing will be
560
     *                         rethrown wrapped into a PropelException.
561
     */
562 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...
563
    {
564
        if (null === $con) {
565
            $con = Propel::getServiceContainer()->getWriteConnection(ChannelTableMap::DATABASE_NAME);
566
        }
567
568
        $criteria = $this;
569
570
        // Set the correct dbName
571
        $criteria->setDbName(ChannelTableMap::DATABASE_NAME);
572
573
        // use transaction because $criteria could contain info
574
        // for more than one table or we could emulating ON DELETE CASCADE, etc.
575
        return $con->transaction(function () use ($con, $criteria) {
576
            $affectedRows = 0; // initialize var to track total num of affected rows
577
578
            ChannelTableMap::removeInstanceFromPool($criteria);
579
580
            $affectedRows += ModelCriteria::delete($con);
581
            ChannelTableMap::clearRelatedInstancePool();
582
583
            return $affectedRows;
584
        });
585
    }
586
587
} // ChannelQuery
588