TaskTableMap   A
last analyzed

Complexity

Total Complexity 33

Size/Duplication

Total Lines 385
Duplicated Lines 31.69 %

Coupling/Cohesion

Components 2
Dependencies 13

Importance

Changes 0
Metric Value
wmc 33
c 0
b 0
f 0
lcom 2
cbo 13
dl 122
loc 385
rs 9.3999

13 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 14 1
A buildRelations() 0 3 1
A getPrimaryKeyHashFromRow() 9 9 4
A getPrimaryKeyFromRow() 8 8 2
A getOMClass() 0 4 2
A populateObject() 18 18 2
B populateObjects() 25 25 3
A addSelectColumns() 0 12 2
A getTableMap() 0 4 1
A buildTableMap() 7 7 2
C doDelete() 29 29 7
A doDeleteAll() 0 4 1
B doInsert() 26 26 5

How to fix   Duplicated Code   

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:

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 29 and the first side effect is on line 416.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace Core\Models\Task\Map;
4
5
use Core\Models\Task\Task;
6
use Core\Models\Task\TaskQuery;
7
use Propel\Runtime\Propel;
8
use Propel\Runtime\ActiveQuery\Criteria;
9
use Propel\Runtime\ActiveQuery\InstancePoolTrait;
10
use Propel\Runtime\Connection\ConnectionInterface;
11
use Propel\Runtime\DataFetcher\DataFetcherInterface;
12
use Propel\Runtime\Exception\PropelException;
13
use Propel\Runtime\Map\RelationMap;
14
use Propel\Runtime\Map\TableMap;
15
use Propel\Runtime\Map\TableMapTrait;
16
17
18
/**
19
 * This class defines the structure of the 'tasks' table.
20
 *
21
 *
22
 *
23
 * This map class is used by Propel to do runtime db structure discovery.
24
 * For example, the createSelectSql() method checks the type of a given column used in an
25
 * ORDER BY clause to know whether it needs to apply SQL to make the ORDER BY case-insensitive
26
 * (i.e. if it's a text column type).
27
 *
28
 */
29
class TaskTableMap extends TableMap
30
{
31
    use InstancePoolTrait;
32
    use TableMapTrait;
33
34
    /**
35
     * The (dot-path) name of this class
36
     */
37
    const CLASS_NAME = 'Models.Task.Map.TaskTableMap';
38
39
    /**
40
     * The default database name for this class
41
     */
42
    const DATABASE_NAME = 'default';
43
44
    /**
45
     * The table name for this class
46
     */
47
    const TABLE_NAME = 'tasks';
48
49
    /**
50
     * The related Propel class for this table
51
     */
52
    const OM_CLASS = '\\Core\\Models\\Task\\Task';
53
54
    /**
55
     * A class that can be returned by this tableMap
56
     */
57
    const CLASS_DEFAULT = 'Models.Task.Task';
58
59
    /**
60
     * The total number of columns
61
     */
62
    const NUM_COLUMNS = 3;
63
64
    /**
65
     * The number of lazy-loaded columns
66
     */
67
    const NUM_LAZY_LOAD_COLUMNS = 0;
68
69
    /**
70
     * The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS)
71
     */
72
    const NUM_HYDRATE_COLUMNS = 3;
73
74
    /**
75
     * the column name for the id field
76
     */
77
    const COL_ID = 'tasks.id';
78
79
    /**
80
     * the column name for the created_at field
81
     */
82
    const COL_CREATED_AT = 'tasks.created_at';
83
84
    /**
85
     * the column name for the updated_at field
86
     */
87
    const COL_UPDATED_AT = 'tasks.updated_at';
88
89
    /**
90
     * The default string format for model objects of the related table
91
     */
92
    const DEFAULT_STRING_FORMAT = 'YAML';
93
94
    /**
95
     * holds an array of fieldnames
96
     *
97
     * first dimension keys are the type constants
98
     * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
99
     */
100
    protected static $fieldNames = array (
101
        self::TYPE_PHPNAME       => array('Id', 'CreatedAt', 'UpdatedAt', ),
102
        self::TYPE_CAMELNAME     => array('id', 'createdAt', 'updatedAt', ),
103
        self::TYPE_COLNAME       => array(TaskTableMap::COL_ID, TaskTableMap::COL_CREATED_AT, TaskTableMap::COL_UPDATED_AT, ),
104
        self::TYPE_FIELDNAME     => array('id', 'created_at', 'updated_at', ),
105
        self::TYPE_NUM           => array(0, 1, 2, )
106
    );
107
108
    /**
109
     * holds an array of keys for quick access to the fieldnames array
110
     *
111
     * first dimension keys are the type constants
112
     * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0
113
     */
114
    protected static $fieldKeys = array (
115
        self::TYPE_PHPNAME       => array('Id' => 0, 'CreatedAt' => 1, 'UpdatedAt' => 2, ),
116
        self::TYPE_CAMELNAME     => array('id' => 0, 'createdAt' => 1, 'updatedAt' => 2, ),
117
        self::TYPE_COLNAME       => array(TaskTableMap::COL_ID => 0, TaskTableMap::COL_CREATED_AT => 1, TaskTableMap::COL_UPDATED_AT => 2, ),
118
        self::TYPE_FIELDNAME     => array('id' => 0, 'created_at' => 1, 'updated_at' => 2, ),
119
        self::TYPE_NUM           => array(0, 1, 2, )
120
    );
121
122
    /**
123
     * Initialize the table attributes and columns
124
     * Relations are not initialized by this method since they are lazy loaded
125
     *
126
     * @return void
127
     * @throws PropelException
128
     */
129
    public function initialize()
130
    {
131
        // attributes
132
        $this->setName('tasks');
133
        $this->setPhpName('Task');
134
        $this->setIdentifierQuoting(false);
135
        $this->setClassName('\\Core\\Models\\Task\\Task');
136
        $this->setPackage('Models.Task');
137
        $this->setUseIdGenerator(true);
138
        // columns
139
        $this->addPrimaryKey('id', 'Id', 'INTEGER', true, 10, null);
140
        $this->addColumn('created_at', 'CreatedAt', 'TIMESTAMP', false, null, null);
141
        $this->addColumn('updated_at', 'UpdatedAt', 'TIMESTAMP', false, null, null);
142
    } // initialize()
143
144
    /**
145
     * Build the RelationMap objects for this table relationships
146
     */
147
    public function buildRelations()
148
    {
149
    } // buildRelations()
150
151
    /**
152
     * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table.
153
     *
154
     * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with
155
     * a multi-column primary key, a serialize()d version of the primary key will be returned.
156
     *
157
     * @param array  $row       resultset row.
158
     * @param int    $offset    The 0-based offset for reading from the resultset row.
159
     * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
160
     *                           TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM
161
     *
162
     * @return string The primary key hash of the row
163
     */
164 View Code Duplication
    public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM)
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...
165
    {
166
        // If the PK cannot be derived from the row, return NULL.
167
        if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) {
168
            return null;
169
        }
170
171
        return (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)];
172
    }
173
174
    /**
175
     * Retrieves the primary key from the DB resultset row
176
     * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with
177
     * a multi-column primary key, an array of the primary key columns will be returned.
178
     *
179
     * @param array  $row       resultset row.
180
     * @param int    $offset    The 0-based offset for reading from the resultset row.
181
     * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
182
     *                           TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM
183
     *
184
     * @return mixed The primary key of the row
185
     */
186 View Code Duplication
    public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM)
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...
187
    {
188
        return (int) $row[
189
            $indexType == TableMap::TYPE_NUM
190
                ? 0 + $offset
191
                : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)
192
        ];
193
    }
194
195
    /**
196
     * The class that the tableMap will make instances of.
197
     *
198
     * If $withPrefix is true, the returned path
199
     * uses a dot-path notation which is translated into a path
200
     * relative to a location on the PHP include_path.
201
     * (e.g. path.to.MyClass -> 'path/to/MyClass.php')
202
     *
203
     * @param boolean $withPrefix Whether or not to return the path with the class name
204
     * @return string path.to.ClassName
205
     */
206
    public static function getOMClass($withPrefix = true)
207
    {
208
        return $withPrefix ? TaskTableMap::CLASS_DEFAULT : TaskTableMap::OM_CLASS;
209
    }
210
211
    /**
212
     * Populates an object of the default type or an object that inherit from the default.
213
     *
214
     * @param array  $row       row returned by DataFetcher->fetch().
215
     * @param int    $offset    The 0-based offset for reading from the resultset row.
216
     * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType().
217
                                 One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
218
     *                           TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
219
     *
220
     * @throws PropelException Any exceptions caught during processing will be
221
     *                         rethrown wrapped into a PropelException.
222
     * @return array           (Task object, last column rank)
223
     */
224 View Code Duplication
    public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM)
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...
225
    {
226
        $key = TaskTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType);
227
        if (null !== ($obj = TaskTableMap::getInstanceFromPool($key))) {
228
            // We no longer rehydrate the object, since this can cause data loss.
229
            // See http://www.propelorm.org/ticket/509
230
            // $obj->hydrate($row, $offset, true); // rehydrate
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
231
            $col = $offset + TaskTableMap::NUM_HYDRATE_COLUMNS;
232
        } else {
233
            $cls = TaskTableMap::OM_CLASS;
234
            /** @var Task $obj */
235
            $obj = new $cls();
236
            $col = $obj->hydrate($row, $offset, false, $indexType);
237
            TaskTableMap::addInstanceToPool($obj, $key);
238
        }
239
240
        return array($obj, $col);
241
    }
242
243
    /**
244
     * The returned array will contain objects of the default type or
245
     * objects that inherit from the default.
246
     *
247
     * @param DataFetcherInterface $dataFetcher
248
     * @return array
249
     * @throws PropelException Any exceptions caught during processing will be
250
     *                         rethrown wrapped into a PropelException.
251
     */
252 View Code Duplication
    public static function populateObjects(DataFetcherInterface $dataFetcher)
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...
253
    {
254
        $results = array();
255
256
        // set the class once to avoid overhead in the loop
257
        $cls = static::getOMClass(false);
258
        // populate the object(s)
259
        while ($row = $dataFetcher->fetch()) {
260
            $key = TaskTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType());
261
            if (null !== ($obj = TaskTableMap::getInstanceFromPool($key))) {
262
                // We no longer rehydrate the object, since this can cause data loss.
263
                // See http://www.propelorm.org/ticket/509
264
                // $obj->hydrate($row, 0, true); // rehydrate
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
265
                $results[] = $obj;
266
            } else {
267
                /** @var Task $obj */
268
                $obj = new $cls();
269
                $obj->hydrate($row);
270
                $results[] = $obj;
271
                TaskTableMap::addInstanceToPool($obj, $key);
272
            } // if key exists
273
        }
274
275
        return $results;
276
    }
277
    /**
278
     * Add all the columns needed to create a new object.
279
     *
280
     * Note: any columns that were marked with lazyLoad="true" in the
281
     * XML schema will not be added to the select list and only loaded
282
     * on demand.
283
     *
284
     * @param Criteria $criteria object containing the columns to add.
285
     * @param string   $alias    optional table alias
286
     * @throws PropelException Any exceptions caught during processing will be
287
     *                         rethrown wrapped into a PropelException.
288
     */
289
    public static function addSelectColumns(Criteria $criteria, $alias = null)
290
    {
291
        if (null === $alias) {
292
            $criteria->addSelectColumn(TaskTableMap::COL_ID);
293
            $criteria->addSelectColumn(TaskTableMap::COL_CREATED_AT);
294
            $criteria->addSelectColumn(TaskTableMap::COL_UPDATED_AT);
295
        } else {
296
            $criteria->addSelectColumn($alias . '.id');
297
            $criteria->addSelectColumn($alias . '.created_at');
298
            $criteria->addSelectColumn($alias . '.updated_at');
299
        }
300
    }
301
302
    /**
303
     * Returns the TableMap related to this object.
304
     * This method is not needed for general use but a specific application could have a need.
305
     * @return TableMap
306
     * @throws PropelException Any exceptions caught during processing will be
307
     *                         rethrown wrapped into a PropelException.
308
     */
309
    public static function getTableMap()
310
    {
311
        return Propel::getServiceContainer()->getDatabaseMap(TaskTableMap::DATABASE_NAME)->getTable(TaskTableMap::TABLE_NAME);
312
    }
313
314
    /**
315
     * Add a TableMap instance to the database for this tableMap class.
316
     */
317 View Code Duplication
    public static function buildTableMap()
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
        $dbMap = Propel::getServiceContainer()->getDatabaseMap(TaskTableMap::DATABASE_NAME);
320
        if (!$dbMap->hasTable(TaskTableMap::TABLE_NAME)) {
321
            $dbMap->addTableObject(new TaskTableMap());
322
        }
323
    }
324
325
    /**
326
     * Performs a DELETE on the database, given a Task or Criteria object OR a primary key value.
327
     *
328
     * @param mixed               $values Criteria or Task object or primary key or array of primary keys
329
     *              which is used to create the DELETE statement
330
     * @param  ConnectionInterface $con the connection to use
331
     * @return int             The number of affected rows (if supported by underlying database driver).  This includes CASCADE-related rows
332
     *                         if supported by native driver or if emulated using Propel.
333
     * @throws PropelException Any exceptions caught during processing will be
334
     *                         rethrown wrapped into a PropelException.
335
     */
336 View Code Duplication
     public static function doDelete($values, 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...
337
     {
338
        if (null === $con) {
339
            $con = Propel::getServiceContainer()->getWriteConnection(TaskTableMap::DATABASE_NAME);
340
        }
341
342
        if ($values instanceof Criteria) {
343
            // rename for clarity
344
            $criteria = $values;
345
        } elseif ($values instanceof \Core\Models\Task\Task) { // it's a model object
346
            // create criteria based on pk values
347
            $criteria = $values->buildPkeyCriteria();
348
        } else { // it's a primary key, or an array of pks
349
            $criteria = new Criteria(TaskTableMap::DATABASE_NAME);
350
            $criteria->add(TaskTableMap::COL_ID, (array) $values, Criteria::IN);
351
        }
352
353
        $query = TaskQuery::create()->mergeWith($criteria);
354
355
        if ($values instanceof Criteria) {
356
            TaskTableMap::clearInstancePool();
357
        } elseif (!is_object($values)) { // it's a primary key, or an array of pks
358
            foreach ((array) $values as $singleval) {
359
                TaskTableMap::removeInstanceFromPool($singleval);
360
            }
361
        }
362
363
        return $query->delete($con);
364
    }
365
366
    /**
367
     * Deletes all rows from the tasks table.
368
     *
369
     * @param ConnectionInterface $con the connection to use
370
     * @return int The number of affected rows (if supported by underlying database driver).
371
     */
372
    public static function doDeleteAll(ConnectionInterface $con = null)
373
    {
374
        return TaskQuery::create()->doDeleteAll($con);
375
    }
376
377
    /**
378
     * Performs an INSERT on the database, given a Task or Criteria object.
379
     *
380
     * @param mixed               $criteria Criteria or Task object containing data that is used to create the INSERT statement.
381
     * @param ConnectionInterface $con the ConnectionInterface connection to use
382
     * @return mixed           The new primary key.
383
     * @throws PropelException Any exceptions caught during processing will be
384
     *                         rethrown wrapped into a PropelException.
385
     */
386 View Code Duplication
    public static function doInsert($criteria, 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...
387
    {
388
        if (null === $con) {
389
            $con = Propel::getServiceContainer()->getWriteConnection(TaskTableMap::DATABASE_NAME);
390
        }
391
392
        if ($criteria instanceof Criteria) {
393
            $criteria = clone $criteria; // rename for clarity
394
        } else {
395
            $criteria = $criteria->buildCriteria(); // build Criteria from Task object
396
        }
397
398
        if ($criteria->containsKey(TaskTableMap::COL_ID) && $criteria->keyContainsValue(TaskTableMap::COL_ID) ) {
399
            throw new PropelException('Cannot insert a value for auto-increment primary key ('.TaskTableMap::COL_ID.')');
400
        }
401
402
403
        // Set the correct dbName
404
        $query = TaskQuery::create()->mergeWith($criteria);
405
406
        // use transaction because $criteria could contain info
407
        // for more than one table (I guess, conceivably)
408
        return $con->transaction(function () use ($con, $query) {
409
            return $query->doInsert($con);
410
        });
411
    }
412
413
} // TaskTableMap
414
// This is the static code needed to register the TableMap for this table with the main Propel class.
415
//
416
TaskTableMap::buildTableMap();
417