Completed
Pull Request — master (#288)
by
unknown
03:49
created

Gamecurrency::fromArray()   F

Complexity

Conditions 10
Paths 512

Size

Total Lines 32
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 3.2187
c 0
b 0
f 0
cc 10
eloc 20
nc 512
nop 2

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace eXpansion\Framework\PlayersBundle\Model\Base;
4
5
use \DateTime;
6
use \Exception;
7
use \PDO;
8
use Propel\Runtime\Propel;
9
use Propel\Runtime\ActiveQuery\Criteria;
10
use Propel\Runtime\ActiveQuery\ModelCriteria;
11
use Propel\Runtime\ActiveRecord\ActiveRecordInterface;
12
use Propel\Runtime\Collection\Collection;
13
use Propel\Runtime\Connection\ConnectionInterface;
14
use Propel\Runtime\Exception\BadMethodCallException;
15
use Propel\Runtime\Exception\LogicException;
16
use Propel\Runtime\Exception\PropelException;
17
use Propel\Runtime\Map\TableMap;
18
use Propel\Runtime\Parser\AbstractParser;
19
use Propel\Runtime\Util\PropelDateTime;
20
use eXpansion\Framework\PlayersBundle\Model\GamecurrencyQuery as ChildGamecurrencyQuery;
21
use eXpansion\Framework\PlayersBundle\Model\Map\GamecurrencyTableMap;
22
23
/**
24
 * Base class that represents a row from the 'gamecurrency' table.
25
 *
26
 *
27
 *
28
 * @package    propel.generator.eXpansion.Framework.PlayersBundle.Model.Base
29
 */
30
abstract class Gamecurrency implements ActiveRecordInterface
31
{
32
    /**
33
     * TableMap class name
34
     */
35
    const TABLE_MAP = '\\eXpansion\\Framework\\PlayersBundle\\Model\\Map\\GamecurrencyTableMap';
36
37
38
    /**
39
     * attribute to determine if this object has previously been saved.
40
     * @var boolean
41
     */
42
    protected $new = true;
43
44
    /**
45
     * attribute to determine whether this object has been deleted.
46
     * @var boolean
47
     */
48
    protected $deleted = false;
49
50
    /**
51
     * The columns that have been modified in current object.
52
     * Tracking modified columns allows us to only update modified columns.
53
     * @var array
54
     */
55
    protected $modifiedColumns = array();
56
57
    /**
58
     * The (virtual) columns that are added at runtime
59
     * The formatters can add supplementary columns based on a resultset
60
     * @var array
61
     */
62
    protected $virtualColumns = array();
63
64
    /**
65
     * The value for the id field.
66
     *
67
     * @var        int
68
     */
69
    protected $id;
70
71
    /**
72
     * The value for the senderlogin field.
73
     *
74
     * @var        string
75
     */
76
    protected $senderlogin;
77
78
    /**
79
     * The value for the receiverlogin field.
80
     *
81
     * @var        string
82
     */
83
    protected $receiverlogin;
84
85
    /**
86
     * The value for the transactionid field.
87
     *
88
     * @var        int
89
     */
90
    protected $transactionid;
91
92
    /**
93
     * The value for the billid field.
94
     *
95
     * @var        int
96
     */
97
    protected $billid;
98
99
    /**
100
     * The value for the amount field.
101
     *
102
     * @var        int
103
     */
104
    protected $amount;
105
106
    /**
107
     * The value for the message field.
108
     *
109
     * @var        string
110
     */
111
    protected $message;
112
113
    /**
114
     * The value for the status field.
115
     *
116
     * @var        int
117
     */
118
    protected $status;
119
120
    /**
121
     * The value for the datetime field.
122
     *
123
     * @var        DateTime
124
     */
125
    protected $datetime;
126
127
    /**
128
     * Flag to prevent endless save loop, if this object is referenced
129
     * by another object which falls in this transaction.
130
     *
131
     * @var boolean
132
     */
133
    protected $alreadyInSave = false;
134
135
    /**
136
     * Initializes internal state of eXpansion\Framework\PlayersBundle\Model\Base\Gamecurrency object.
137
     */
138
    public function __construct()
139
    {
140
    }
141
142
    /**
143
     * Returns whether the object has been modified.
144
     *
145
     * @return boolean True if the object has been modified.
146
     */
147
    public function isModified()
148
    {
149
        return !!$this->modifiedColumns;
150
    }
151
152
    /**
153
     * Has specified column been modified?
154
     *
155
     * @param  string  $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID
156
     * @return boolean True if $col has been modified.
157
     */
158
    public function isColumnModified($col)
159
    {
160
        return $this->modifiedColumns && isset($this->modifiedColumns[$col]);
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->modifiedColumns 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...
161
    }
162
163
    /**
164
     * Get the columns that have been modified in this object.
165
     * @return array A unique list of the modified column names for this object.
166
     */
167
    public function getModifiedColumns()
168
    {
169
        return $this->modifiedColumns ? array_keys($this->modifiedColumns) : [];
170
    }
171
172
    /**
173
     * Returns whether the object has ever been saved.  This will
174
     * be false, if the object was retrieved from storage or was created
175
     * and then saved.
176
     *
177
     * @return boolean true, if the object has never been persisted.
178
     */
179
    public function isNew()
180
    {
181
        return $this->new;
182
    }
183
184
    /**
185
     * Setter for the isNew attribute.  This method will be called
186
     * by Propel-generated children and objects.
187
     *
188
     * @param boolean $b the state of the object.
189
     */
190
    public function setNew($b)
191
    {
192
        $this->new = (boolean) $b;
193
    }
194
195
    /**
196
     * Whether this object has been deleted.
197
     * @return boolean The deleted state of this object.
198
     */
199
    public function isDeleted()
200
    {
201
        return $this->deleted;
202
    }
203
204
    /**
205
     * Specify whether this object has been deleted.
206
     * @param  boolean $b The deleted state of this object.
207
     * @return void
208
     */
209
    public function setDeleted($b)
210
    {
211
        $this->deleted = (boolean) $b;
212
    }
213
214
    /**
215
     * Sets the modified state for the object to be false.
216
     * @param  string $col If supplied, only the specified column is reset.
217
     * @return void
218
     */
219
    public function resetModified($col = null)
220
    {
221
        if (null !== $col) {
222
            if (isset($this->modifiedColumns[$col])) {
223
                unset($this->modifiedColumns[$col]);
224
            }
225
        } else {
226
            $this->modifiedColumns = array();
227
        }
228
    }
229
230
    /**
231
     * Compares this with another <code>Gamecurrency</code> instance.  If
232
     * <code>obj</code> is an instance of <code>Gamecurrency</code>, delegates to
233
     * <code>equals(Gamecurrency)</code>.  Otherwise, returns <code>false</code>.
234
     *
235
     * @param  mixed   $obj The object to compare to.
236
     * @return boolean Whether equal to the object specified.
237
     */
238
    public function equals($obj)
239
    {
240
        if (!$obj instanceof static) {
241
            return false;
242
        }
243
244
        if ($this === $obj) {
245
            return true;
246
        }
247
248
        if (null === $this->getPrimaryKey() || null === $obj->getPrimaryKey()) {
249
            return false;
250
        }
251
252
        return $this->getPrimaryKey() === $obj->getPrimaryKey();
253
    }
254
255
    /**
256
     * Get the associative array of the virtual columns in this object
257
     *
258
     * @return array
259
     */
260
    public function getVirtualColumns()
261
    {
262
        return $this->virtualColumns;
263
    }
264
265
    /**
266
     * Checks the existence of a virtual column in this object
267
     *
268
     * @param  string  $name The virtual column name
269
     * @return boolean
270
     */
271
    public function hasVirtualColumn($name)
272
    {
273
        return array_key_exists($name, $this->virtualColumns);
274
    }
275
276
    /**
277
     * Get the value of a virtual column in this object
278
     *
279
     * @param  string $name The virtual column name
280
     * @return mixed
281
     *
282
     * @throws PropelException
283
     */
284
    public function getVirtualColumn($name)
285
    {
286
        if (!$this->hasVirtualColumn($name)) {
287
            throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name));
288
        }
289
290
        return $this->virtualColumns[$name];
291
    }
292
293
    /**
294
     * Set the value of a virtual column in this object
295
     *
296
     * @param string $name  The virtual column name
297
     * @param mixed  $value The value to give to the virtual column
298
     *
299
     * @return $this|Gamecurrency The current object, for fluid interface
300
     */
301
    public function setVirtualColumn($name, $value)
302
    {
303
        $this->virtualColumns[$name] = $value;
304
305
        return $this;
306
    }
307
308
    /**
309
     * Logs a message using Propel::log().
310
     *
311
     * @param  string  $msg
312
     * @param  int     $priority One of the Propel::LOG_* logging levels
313
     * @return boolean
314
     */
315
    protected function log($msg, $priority = Propel::LOG_INFO)
316
    {
317
        return Propel::log(get_class($this) . ': ' . $msg, $priority);
318
    }
319
320
    /**
321
     * Export the current object properties to a string, using a given parser format
322
     * <code>
323
     * $book = BookQuery::create()->findPk(9012);
324
     * echo $book->exportTo('JSON');
325
     *  => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}');
326
     * </code>
327
     *
328
     * @param  mixed   $parser                 A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV')
329
     * @param  boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE.
330
     * @return string  The exported data
331
     */
332
    public function exportTo($parser, $includeLazyLoadColumns = true)
333
    {
334
        if (!$parser instanceof AbstractParser) {
335
            $parser = AbstractParser::getParser($parser);
336
        }
337
338
        return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true));
0 ignored issues
show
Unused Code introduced by
The call to Gamecurrency::toArray() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Bug introduced by
It seems like $this->toArray(\Propel\R...Columns, array(), true) targeting eXpansion\Framework\Play...Gamecurrency::toArray() can also be of type string; however, Propel\Runtime\Parser\AbstractParser::fromArray() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
339
    }
340
341
    /**
342
     * Clean up internal collections prior to serializing
343
     * Avoids recursive loops that turn into segmentation faults when serializing
344
     */
345
    public function __sleep()
346
    {
347
        $this->clearAllReferences();
0 ignored issues
show
Unused Code introduced by
The call to the method eXpansion\Framework\Play...y::clearAllReferences() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
348
349
        $cls = new \ReflectionClass($this);
350
        $propertyNames = [];
351
        $serializableProperties = array_diff($cls->getProperties(), $cls->getProperties(\ReflectionProperty::IS_STATIC));
352
353
        foreach($serializableProperties as $property) {
354
            $propertyNames[] = $property->getName();
355
        }
356
357
        return $propertyNames;
358
    }
359
360
    /**
361
     * Get the [id] column value.
362
     *
363
     * @return int
364
     */
365
    public function getId()
366
    {
367
        return $this->id;
368
    }
369
370
    /**
371
     * Get the [senderlogin] column value.
372
     *
373
     * @return string
374
     */
375
    public function getSenderlogin()
376
    {
377
        return $this->senderlogin;
378
    }
379
380
    /**
381
     * Get the [receiverlogin] column value.
382
     *
383
     * @return string
384
     */
385
    public function getReceiverlogin()
386
    {
387
        return $this->receiverlogin;
388
    }
389
390
    /**
391
     * Get the [transactionid] column value.
392
     *
393
     * @return int
394
     */
395
    public function getTransactionid()
396
    {
397
        return $this->transactionid;
398
    }
399
400
    /**
401
     * Get the [billid] column value.
402
     *
403
     * @return int
404
     */
405
    public function getBillid()
406
    {
407
        return $this->billid;
408
    }
409
410
    /**
411
     * Get the [amount] column value.
412
     *
413
     * @return int
414
     */
415
    public function getAmount()
416
    {
417
        return $this->amount;
418
    }
419
420
    /**
421
     * Get the [message] column value.
422
     *
423
     * @return string
424
     */
425
    public function getMessage()
426
    {
427
        return $this->message;
428
    }
429
430
    /**
431
     * Get the [status] column value.
432
     *
433
     * @return int
434
     */
435
    public function getStatus()
436
    {
437
        return $this->status;
438
    }
439
440
    /**
441
     * Get the [optionally formatted] temporal [datetime] column value.
442
     *
443
     *
444
     * @param      string $format The date/time format string (either date()-style or strftime()-style).
445
     *                            If format is NULL, then the raw DateTime object will be returned.
446
     *
447
     * @return string|DateTime Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00
448
     *
449
     * @throws PropelException - if unable to parse/validate the date/time value.
450
     */
451
    public function getDatetime($format = NULL)
452
    {
453
        if ($format === null) {
454
            return $this->datetime;
455
        } else {
456
            return $this->datetime instanceof \DateTimeInterface ? $this->datetime->format($format) : null;
457
        }
458
    }
459
460
    /**
461
     * Set the value of [id] column.
462
     *
463
     * @param int $v new value
464
     * @return $this|\eXpansion\Framework\PlayersBundle\Model\Gamecurrency The current object (for fluent API support)
465
     */
466 View Code Duplication
    public function setId($v)
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...
467
    {
468
        if ($v !== null) {
469
            $v = (int) $v;
470
        }
471
472
        if ($this->id !== $v) {
473
            $this->id = $v;
474
            $this->modifiedColumns[GamecurrencyTableMap::COL_ID] = true;
475
        }
476
477
        return $this;
478
    } // setId()
479
480
    /**
481
     * Set the value of [senderlogin] column.
482
     *
483
     * @param string $v new value
484
     * @return $this|\eXpansion\Framework\PlayersBundle\Model\Gamecurrency The current object (for fluent API support)
485
     */
486 View Code Duplication
    public function setSenderlogin($v)
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...
487
    {
488
        if ($v !== null) {
489
            $v = (string) $v;
490
        }
491
492
        if ($this->senderlogin !== $v) {
493
            $this->senderlogin = $v;
494
            $this->modifiedColumns[GamecurrencyTableMap::COL_SENDERLOGIN] = true;
495
        }
496
497
        return $this;
498
    } // setSenderlogin()
499
500
    /**
501
     * Set the value of [receiverlogin] column.
502
     *
503
     * @param string $v new value
504
     * @return $this|\eXpansion\Framework\PlayersBundle\Model\Gamecurrency The current object (for fluent API support)
505
     */
506 View Code Duplication
    public function setReceiverlogin($v)
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...
507
    {
508
        if ($v !== null) {
509
            $v = (string) $v;
510
        }
511
512
        if ($this->receiverlogin !== $v) {
513
            $this->receiverlogin = $v;
514
            $this->modifiedColumns[GamecurrencyTableMap::COL_RECEIVERLOGIN] = true;
515
        }
516
517
        return $this;
518
    } // setReceiverlogin()
519
520
    /**
521
     * Set the value of [transactionid] column.
522
     *
523
     * @param int $v new value
524
     * @return $this|\eXpansion\Framework\PlayersBundle\Model\Gamecurrency The current object (for fluent API support)
525
     */
526 View Code Duplication
    public function setTransactionid($v)
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...
527
    {
528
        if ($v !== null) {
529
            $v = (int) $v;
530
        }
531
532
        if ($this->transactionid !== $v) {
533
            $this->transactionid = $v;
534
            $this->modifiedColumns[GamecurrencyTableMap::COL_TRANSACTIONID] = true;
535
        }
536
537
        return $this;
538
    } // setTransactionid()
539
540
    /**
541
     * Set the value of [billid] column.
542
     *
543
     * @param int $v new value
544
     * @return $this|\eXpansion\Framework\PlayersBundle\Model\Gamecurrency The current object (for fluent API support)
545
     */
546 View Code Duplication
    public function setBillid($v)
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...
547
    {
548
        if ($v !== null) {
549
            $v = (int) $v;
550
        }
551
552
        if ($this->billid !== $v) {
553
            $this->billid = $v;
554
            $this->modifiedColumns[GamecurrencyTableMap::COL_BILLID] = true;
555
        }
556
557
        return $this;
558
    } // setBillid()
559
560
    /**
561
     * Set the value of [amount] column.
562
     *
563
     * @param int $v new value
564
     * @return $this|\eXpansion\Framework\PlayersBundle\Model\Gamecurrency The current object (for fluent API support)
565
     */
566 View Code Duplication
    public function setAmount($v)
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...
567
    {
568
        if ($v !== null) {
569
            $v = (int) $v;
570
        }
571
572
        if ($this->amount !== $v) {
573
            $this->amount = $v;
574
            $this->modifiedColumns[GamecurrencyTableMap::COL_AMOUNT] = true;
575
        }
576
577
        return $this;
578
    } // setAmount()
579
580
    /**
581
     * Set the value of [message] column.
582
     *
583
     * @param string $v new value
584
     * @return $this|\eXpansion\Framework\PlayersBundle\Model\Gamecurrency The current object (for fluent API support)
585
     */
586 View Code Duplication
    public function setMessage($v)
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...
587
    {
588
        if ($v !== null) {
589
            $v = (string) $v;
590
        }
591
592
        if ($this->message !== $v) {
593
            $this->message = $v;
594
            $this->modifiedColumns[GamecurrencyTableMap::COL_MESSAGE] = true;
595
        }
596
597
        return $this;
598
    } // setMessage()
599
600
    /**
601
     * Set the value of [status] column.
602
     *
603
     * @param int $v new value
604
     * @return $this|\eXpansion\Framework\PlayersBundle\Model\Gamecurrency The current object (for fluent API support)
605
     */
606 View Code Duplication
    public function setStatus($v)
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...
607
    {
608
        if ($v !== null) {
609
            $v = (int) $v;
610
        }
611
612
        if ($this->status !== $v) {
613
            $this->status = $v;
614
            $this->modifiedColumns[GamecurrencyTableMap::COL_STATUS] = true;
615
        }
616
617
        return $this;
618
    } // setStatus()
619
620
    /**
621
     * Sets the value of [datetime] column to a normalized version of the date/time value specified.
622
     *
623
     * @param  mixed $v string, integer (timestamp), or \DateTimeInterface value.
624
     *               Empty strings are treated as NULL.
625
     * @return $this|\eXpansion\Framework\PlayersBundle\Model\Gamecurrency The current object (for fluent API support)
626
     */
627
    public function setDatetime($v)
628
    {
629
        $dt = PropelDateTime::newInstance($v, null, 'DateTime');
630
        if ($this->datetime !== null || $dt !== null) {
631
            if ($this->datetime === null || $dt === null || $dt->format("Y-m-d H:i:s.u") !== $this->datetime->format("Y-m-d H:i:s.u")) {
632
                $this->datetime = $dt === null ? null : clone $dt;
0 ignored issues
show
Documentation Bug introduced by
It seems like $dt === null ? null : clone $dt can also be of type false. However, the property $datetime is declared as type object<DateTime>. Maybe add an additional type check?

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

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

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

class Id
{
    public $id;

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

}

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

$account_id = false;

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

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
633
                $this->modifiedColumns[GamecurrencyTableMap::COL_DATETIME] = true;
634
            }
635
        } // if either are not null
636
637
        return $this;
638
    } // setDatetime()
639
640
    /**
641
     * Indicates whether the columns in this object are only set to default values.
642
     *
643
     * This method can be used in conjunction with isModified() to indicate whether an object is both
644
     * modified _and_ has some values set which are non-default.
645
     *
646
     * @return boolean Whether the columns in this object are only been set with default values.
647
     */
648
    public function hasOnlyDefaultValues()
649
    {
650
        // otherwise, everything was equal, so return TRUE
651
        return true;
652
    } // hasOnlyDefaultValues()
653
654
    /**
655
     * Hydrates (populates) the object variables with values from the database resultset.
656
     *
657
     * An offset (0-based "start column") is specified so that objects can be hydrated
658
     * with a subset of the columns in the resultset rows.  This is needed, for example,
659
     * for results of JOIN queries where the resultset row includes columns from two or
660
     * more tables.
661
     *
662
     * @param array   $row       The row returned by DataFetcher->fetch().
663
     * @param int     $startcol  0-based offset column which indicates which restultset column to start with.
664
     * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
665
     * @param string  $indexType The index type of $row. Mostly DataFetcher->getIndexType().
666
                                  One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
667
     *                            TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
668
     *
669
     * @return int             next starting column
670
     * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
671
     */
672
    public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM)
673
    {
674
        try {
675
676
            $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : GamecurrencyTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)];
677
            $this->id = (null !== $col) ? (int) $col : null;
678
679
            $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : GamecurrencyTableMap::translateFieldName('Senderlogin', TableMap::TYPE_PHPNAME, $indexType)];
680
            $this->senderlogin = (null !== $col) ? (string) $col : null;
681
682
            $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : GamecurrencyTableMap::translateFieldName('Receiverlogin', TableMap::TYPE_PHPNAME, $indexType)];
683
            $this->receiverlogin = (null !== $col) ? (string) $col : null;
684
685
            $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : GamecurrencyTableMap::translateFieldName('Transactionid', TableMap::TYPE_PHPNAME, $indexType)];
686
            $this->transactionid = (null !== $col) ? (int) $col : null;
687
688
            $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : GamecurrencyTableMap::translateFieldName('Billid', TableMap::TYPE_PHPNAME, $indexType)];
689
            $this->billid = (null !== $col) ? (int) $col : null;
690
691
            $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : GamecurrencyTableMap::translateFieldName('Amount', TableMap::TYPE_PHPNAME, $indexType)];
692
            $this->amount = (null !== $col) ? (int) $col : null;
693
694
            $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : GamecurrencyTableMap::translateFieldName('Message', TableMap::TYPE_PHPNAME, $indexType)];
695
            $this->message = (null !== $col) ? (string) $col : null;
696
697
            $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : GamecurrencyTableMap::translateFieldName('Status', TableMap::TYPE_PHPNAME, $indexType)];
698
            $this->status = (null !== $col) ? (int) $col : null;
699
700
            $col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : GamecurrencyTableMap::translateFieldName('Datetime', TableMap::TYPE_PHPNAME, $indexType)];
701
            if ($col === '0000-00-00 00:00:00') {
702
                $col = null;
703
            }
704
            $this->datetime = (null !== $col) ? PropelDateTime::newInstance($col, null, 'DateTime') : null;
705
            $this->resetModified();
706
707
            $this->setNew(false);
708
709
            if ($rehydrate) {
710
                $this->ensureConsistency();
711
            }
712
713
            return $startcol + 9; // 9 = GamecurrencyTableMap::NUM_HYDRATE_COLUMNS.
714
715
        } catch (Exception $e) {
716
            throw new PropelException(sprintf('Error populating %s object', '\\eXpansion\\Framework\\PlayersBundle\\Model\\Gamecurrency'), 0, $e);
717
        }
718
    }
719
720
    /**
721
     * Checks and repairs the internal consistency of the object.
722
     *
723
     * This method is executed after an already-instantiated object is re-hydrated
724
     * from the database.  It exists to check any foreign keys to make sure that
725
     * the objects related to the current object are correct based on foreign key.
726
     *
727
     * You can override this method in the stub class, but you should always invoke
728
     * the base method from the overridden method (i.e. parent::ensureConsistency()),
729
     * in case your model changes.
730
     *
731
     * @throws PropelException
732
     */
733
    public function ensureConsistency()
734
    {
735
    } // ensureConsistency
736
737
    /**
738
     * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
739
     *
740
     * This will only work if the object has been saved and has a valid primary key set.
741
     *
742
     * @param      boolean $deep (optional) Whether to also de-associated any related objects.
743
     * @param      ConnectionInterface $con (optional) The ConnectionInterface connection to use.
744
     * @return void
745
     * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
746
     */
747
    public function reload($deep = false, ConnectionInterface $con = null)
748
    {
749
        if ($this->isDeleted()) {
750
            throw new PropelException("Cannot reload a deleted object.");
751
        }
752
753
        if ($this->isNew()) {
754
            throw new PropelException("Cannot reload an unsaved object.");
755
        }
756
757
        if ($con === null) {
758
            $con = Propel::getServiceContainer()->getReadConnection(GamecurrencyTableMap::DATABASE_NAME);
759
        }
760
761
        // We don't need to alter the object instance pool; we're just modifying this instance
762
        // already in the pool.
763
764
        $dataFetcher = ChildGamecurrencyQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Propel\Runtime\ActiveQuery\BaseModelCriteria as the method find() does only exist in the following sub-classes of Propel\Runtime\ActiveQuery\BaseModelCriteria: Propel\Bundle\PropelBund...es\Model\Base\BookQuery, Propel\Bundle\PropelBund...ixtures\Model\BookQuery, Propel\Runtime\ActiveQuery\ModelCriteria, eXpansion\Framework\Play...\Base\GamecurrencyQuery, eXpansion\Framework\Play...Model\GamecurrencyQuery. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
765
        $row = $dataFetcher->fetch();
766
        $dataFetcher->close();
767
        if (!$row) {
768
            throw new PropelException('Cannot find matching row in the database to reload object values.');
769
        }
770
        $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate
771
772
        if ($deep) {  // also de-associate any related objects?
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
773
774
        } // if (deep)
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
775
    }
776
777
    /**
778
     * Removes this object from datastore and sets delete attribute.
779
     *
780
     * @param      ConnectionInterface $con
781
     * @return void
782
     * @throws PropelException
783
     * @see Gamecurrency::setDeleted()
784
     * @see Gamecurrency::isDeleted()
785
     */
786
    public function delete(ConnectionInterface $con = null)
787
    {
788
        if ($this->isDeleted()) {
789
            throw new PropelException("This object has already been deleted.");
790
        }
791
792
        if ($con === null) {
793
            $con = Propel::getServiceContainer()->getWriteConnection(GamecurrencyTableMap::DATABASE_NAME);
794
        }
795
796
        $con->transaction(function () use ($con) {
797
            $deleteQuery = ChildGamecurrencyQuery::create()
798
                ->filterByPrimaryKey($this->getPrimaryKey());
799
            $ret = $this->preDelete($con);
800
            if ($ret) {
801
                $deleteQuery->delete($con);
802
                $this->postDelete($con);
803
                $this->setDeleted(true);
804
            }
805
        });
806
    }
807
808
    /**
809
     * Persists this object to the database.
810
     *
811
     * If the object is new, it inserts it; otherwise an update is performed.
812
     * All modified related objects will also be persisted in the doSave()
813
     * method.  This method wraps all precipitate database operations in a
814
     * single transaction.
815
     *
816
     * @param      ConnectionInterface $con
817
     * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
818
     * @throws PropelException
819
     * @see doSave()
820
     */
821
    public function save(ConnectionInterface $con = null)
822
    {
823
        if ($this->isDeleted()) {
824
            throw new PropelException("You cannot save an object that has been deleted.");
825
        }
826
827
        if ($con === null) {
828
            $con = Propel::getServiceContainer()->getWriteConnection(GamecurrencyTableMap::DATABASE_NAME);
829
        }
830
831
        return $con->transaction(function () use ($con) {
832
            $ret = $this->preSave($con);
833
            $isInsert = $this->isNew();
834
            if ($isInsert) {
835
                $ret = $ret && $this->preInsert($con);
836
            } else {
837
                $ret = $ret && $this->preUpdate($con);
838
            }
839
            if ($ret) {
840
                $affectedRows = $this->doSave($con);
841
                if ($isInsert) {
842
                    $this->postInsert($con);
843
                } else {
844
                    $this->postUpdate($con);
845
                }
846
                $this->postSave($con);
847
                GamecurrencyTableMap::addInstanceToPool($this);
848
            } else {
849
                $affectedRows = 0;
850
            }
851
852
            return $affectedRows;
853
        });
854
    }
855
856
    /**
857
     * Performs the work of inserting or updating the row in the database.
858
     *
859
     * If the object is new, it inserts it; otherwise an update is performed.
860
     * All related objects are also updated in this method.
861
     *
862
     * @param      ConnectionInterface $con
863
     * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
864
     * @throws PropelException
865
     * @see save()
866
     */
867
    protected function doSave(ConnectionInterface $con)
868
    {
869
        $affectedRows = 0; // initialize var to track total num of affected rows
870
        if (!$this->alreadyInSave) {
871
            $this->alreadyInSave = true;
872
873
            if ($this->isNew() || $this->isModified()) {
874
                // persist changes
875
                if ($this->isNew()) {
876
                    $this->doInsert($con);
877
                    $affectedRows += 1;
878
                } else {
879
                    $affectedRows += $this->doUpdate($con);
880
                }
881
                $this->resetModified();
882
            }
883
884
            $this->alreadyInSave = false;
885
886
        }
887
888
        return $affectedRows;
889
    } // doSave()
890
891
    /**
892
     * Insert the row in the database.
893
     *
894
     * @param      ConnectionInterface $con
895
     *
896
     * @throws PropelException
897
     * @see doSave()
898
     */
899
    protected function doInsert(ConnectionInterface $con)
900
    {
901
        $modifiedColumns = array();
902
        $index = 0;
903
904
        $this->modifiedColumns[GamecurrencyTableMap::COL_ID] = true;
905
        if (null !== $this->id) {
906
            throw new PropelException('Cannot insert a value for auto-increment primary key (' . GamecurrencyTableMap::COL_ID . ')');
907
        }
908
909
         // check the columns in natural order for more readable SQL queries
910
        if ($this->isColumnModified(GamecurrencyTableMap::COL_ID)) {
911
            $modifiedColumns[':p' . $index++]  = 'id';
912
        }
913
        if ($this->isColumnModified(GamecurrencyTableMap::COL_SENDERLOGIN)) {
914
            $modifiedColumns[':p' . $index++]  = 'senderLogin';
915
        }
916
        if ($this->isColumnModified(GamecurrencyTableMap::COL_RECEIVERLOGIN)) {
917
            $modifiedColumns[':p' . $index++]  = 'receiverLogin';
918
        }
919
        if ($this->isColumnModified(GamecurrencyTableMap::COL_TRANSACTIONID)) {
920
            $modifiedColumns[':p' . $index++]  = 'transactionId';
921
        }
922
        if ($this->isColumnModified(GamecurrencyTableMap::COL_BILLID)) {
923
            $modifiedColumns[':p' . $index++]  = 'billId';
924
        }
925
        if ($this->isColumnModified(GamecurrencyTableMap::COL_AMOUNT)) {
926
            $modifiedColumns[':p' . $index++]  = 'amount';
927
        }
928
        if ($this->isColumnModified(GamecurrencyTableMap::COL_MESSAGE)) {
929
            $modifiedColumns[':p' . $index++]  = 'message';
930
        }
931
        if ($this->isColumnModified(GamecurrencyTableMap::COL_STATUS)) {
932
            $modifiedColumns[':p' . $index++]  = 'status';
933
        }
934
        if ($this->isColumnModified(GamecurrencyTableMap::COL_DATETIME)) {
935
            $modifiedColumns[':p' . $index++]  = 'datetime';
936
        }
937
938
        $sql = sprintf(
939
            'INSERT INTO gamecurrency (%s) VALUES (%s)',
940
            implode(', ', $modifiedColumns),
941
            implode(', ', array_keys($modifiedColumns))
942
        );
943
944
        try {
945
            $stmt = $con->prepare($sql);
946
            foreach ($modifiedColumns as $identifier => $columnName) {
947
                switch ($columnName) {
948
                    case 'id':
949
                        $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
950
                        break;
951
                    case 'senderLogin':
952
                        $stmt->bindValue($identifier, $this->senderlogin, PDO::PARAM_STR);
953
                        break;
954
                    case 'receiverLogin':
955
                        $stmt->bindValue($identifier, $this->receiverlogin, PDO::PARAM_STR);
956
                        break;
957
                    case 'transactionId':
958
                        $stmt->bindValue($identifier, $this->transactionid, PDO::PARAM_INT);
959
                        break;
960
                    case 'billId':
961
                        $stmt->bindValue($identifier, $this->billid, PDO::PARAM_INT);
962
                        break;
963
                    case 'amount':
964
                        $stmt->bindValue($identifier, $this->amount, PDO::PARAM_INT);
965
                        break;
966
                    case 'message':
967
                        $stmt->bindValue($identifier, $this->message, PDO::PARAM_STR);
968
                        break;
969
                    case 'status':
970
                        $stmt->bindValue($identifier, $this->status, PDO::PARAM_INT);
971
                        break;
972
                    case 'datetime':
973
                        $stmt->bindValue($identifier, $this->datetime ? $this->datetime->format("Y-m-d H:i:s.u") : null, PDO::PARAM_STR);
974
                        break;
975
                }
976
            }
977
            $stmt->execute();
978
        } catch (Exception $e) {
979
            Propel::log($e->getMessage(), Propel::LOG_ERR);
980
            throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e);
981
        }
982
983
        try {
984
            $pk = $con->lastInsertId();
985
        } catch (Exception $e) {
986
            throw new PropelException('Unable to get autoincrement id.', 0, $e);
987
        }
988
        $this->setId($pk);
989
990
        $this->setNew(false);
991
    }
992
993
    /**
994
     * Update the row in the database.
995
     *
996
     * @param      ConnectionInterface $con
997
     *
998
     * @return Integer Number of updated rows
999
     * @see doSave()
1000
     */
1001
    protected function doUpdate(ConnectionInterface $con)
1002
    {
1003
        $selectCriteria = $this->buildPkeyCriteria();
1004
        $valuesCriteria = $this->buildCriteria();
1005
1006
        return $selectCriteria->doUpdate($valuesCriteria, $con);
0 ignored issues
show
Documentation introduced by
$valuesCriteria is of type object<Propel\Runtime\ActiveQuery\Criteria>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1007
    }
1008
1009
    /**
1010
     * Retrieves a field from the object by name passed in as a string.
1011
     *
1012
     * @param      string $name name
1013
     * @param      string $type The type of fieldname the $name is of:
1014
     *                     one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
1015
     *                     TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
1016
     *                     Defaults to TableMap::TYPE_PHPNAME.
1017
     * @return mixed Value of field.
1018
     */
1019
    public function getByName($name, $type = TableMap::TYPE_PHPNAME)
1020
    {
1021
        $pos = GamecurrencyTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM);
1022
        $field = $this->getByPosition($pos);
1023
1024
        return $field;
1025
    }
1026
1027
    /**
1028
     * Retrieves a field from the object by Position as specified in the xml schema.
1029
     * Zero-based.
1030
     *
1031
     * @param      int $pos position in xml schema
1032
     * @return mixed Value of field at $pos
1033
     */
1034
    public function getByPosition($pos)
1035
    {
1036
        switch ($pos) {
1037
            case 0:
1038
                return $this->getId();
1039
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1040
            case 1:
1041
                return $this->getSenderlogin();
1042
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1043
            case 2:
1044
                return $this->getReceiverlogin();
1045
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1046
            case 3:
1047
                return $this->getTransactionid();
1048
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1049
            case 4:
1050
                return $this->getBillid();
1051
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1052
            case 5:
1053
                return $this->getAmount();
1054
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1055
            case 6:
1056
                return $this->getMessage();
1057
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1058
            case 7:
1059
                return $this->getStatus();
1060
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1061
            case 8:
1062
                return $this->getDatetime();
1063
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1064
            default:
1065
                return null;
1066
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1067
        } // switch()
1068
    }
1069
1070
    /**
1071
     * Exports the object as an array.
1072
     *
1073
     * You can specify the key type of the array by passing one of the class
1074
     * type constants.
1075
     *
1076
     * @param     string  $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
1077
     *                    TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
1078
     *                    Defaults to TableMap::TYPE_PHPNAME.
1079
     * @param     boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE.
1080
     * @param     array $alreadyDumpedObjects List of objects to skip to avoid recursion
1081
     *
1082
     * @return array an associative array containing the field names (as keys) and field values
1083
     */
1084
    public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array())
0 ignored issues
show
Unused Code introduced by
The parameter $includeLazyLoadColumns is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1085
    {
1086
1087
        if (isset($alreadyDumpedObjects['Gamecurrency'][$this->hashCode()])) {
1088
            return '*RECURSION*';
1089
        }
1090
        $alreadyDumpedObjects['Gamecurrency'][$this->hashCode()] = true;
1091
        $keys = GamecurrencyTableMap::getFieldNames($keyType);
1092
        $result = array(
1093
            $keys[0] => $this->getId(),
1094
            $keys[1] => $this->getSenderlogin(),
1095
            $keys[2] => $this->getReceiverlogin(),
1096
            $keys[3] => $this->getTransactionid(),
1097
            $keys[4] => $this->getBillid(),
1098
            $keys[5] => $this->getAmount(),
1099
            $keys[6] => $this->getMessage(),
1100
            $keys[7] => $this->getStatus(),
1101
            $keys[8] => $this->getDatetime(),
1102
        );
1103
        if ($result[$keys[8]] instanceof \DateTime) {
1104
            $result[$keys[8]] = $result[$keys[8]]->format('c');
1105
        }
1106
1107
        $virtualColumns = $this->virtualColumns;
1108
        foreach ($virtualColumns as $key => $virtualColumn) {
1109
            $result[$key] = $virtualColumn;
1110
        }
1111
1112
1113
        return $result;
1114
    }
1115
1116
    /**
1117
     * Sets a field from the object by name passed in as a string.
1118
     *
1119
     * @param  string $name
1120
     * @param  mixed  $value field value
1121
     * @param  string $type The type of fieldname the $name is of:
1122
     *                one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
1123
     *                TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
1124
     *                Defaults to TableMap::TYPE_PHPNAME.
1125
     * @return $this|\eXpansion\Framework\PlayersBundle\Model\Gamecurrency
1126
     */
1127
    public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME)
1128
    {
1129
        $pos = GamecurrencyTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM);
1130
1131
        return $this->setByPosition($pos, $value);
1132
    }
1133
1134
    /**
1135
     * Sets a field from the object by Position as specified in the xml schema.
1136
     * Zero-based.
1137
     *
1138
     * @param  int $pos position in xml schema
1139
     * @param  mixed $value field value
1140
     * @return $this|\eXpansion\Framework\PlayersBundle\Model\Gamecurrency
1141
     */
1142
    public function setByPosition($pos, $value)
1143
    {
1144
        switch ($pos) {
1145
            case 0:
1146
                $this->setId($value);
1147
                break;
1148
            case 1:
1149
                $this->setSenderlogin($value);
1150
                break;
1151
            case 2:
1152
                $this->setReceiverlogin($value);
1153
                break;
1154
            case 3:
1155
                $this->setTransactionid($value);
1156
                break;
1157
            case 4:
1158
                $this->setBillid($value);
1159
                break;
1160
            case 5:
1161
                $this->setAmount($value);
1162
                break;
1163
            case 6:
1164
                $this->setMessage($value);
1165
                break;
1166
            case 7:
1167
                $this->setStatus($value);
1168
                break;
1169
            case 8:
1170
                $this->setDatetime($value);
1171
                break;
1172
        } // switch()
1173
1174
        return $this;
1175
    }
1176
1177
    /**
1178
     * Populates the object using an array.
1179
     *
1180
     * This is particularly useful when populating an object from one of the
1181
     * request arrays (e.g. $_POST).  This method goes through the column
1182
     * names, checking to see whether a matching key exists in populated
1183
     * array. If so the setByName() method is called for that column.
1184
     *
1185
     * You can specify the key type of the array by additionally passing one
1186
     * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
1187
     * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
1188
     * The default key type is the column's TableMap::TYPE_PHPNAME.
1189
     *
1190
     * @param      array  $arr     An array to populate the object from.
1191
     * @param      string $keyType The type of keys the array uses.
1192
     * @return void
1193
     */
1194
    public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME)
1195
    {
1196
        $keys = GamecurrencyTableMap::getFieldNames($keyType);
1197
1198
        if (array_key_exists($keys[0], $arr)) {
1199
            $this->setId($arr[$keys[0]]);
1200
        }
1201
        if (array_key_exists($keys[1], $arr)) {
1202
            $this->setSenderlogin($arr[$keys[1]]);
1203
        }
1204
        if (array_key_exists($keys[2], $arr)) {
1205
            $this->setReceiverlogin($arr[$keys[2]]);
1206
        }
1207
        if (array_key_exists($keys[3], $arr)) {
1208
            $this->setTransactionid($arr[$keys[3]]);
1209
        }
1210
        if (array_key_exists($keys[4], $arr)) {
1211
            $this->setBillid($arr[$keys[4]]);
1212
        }
1213
        if (array_key_exists($keys[5], $arr)) {
1214
            $this->setAmount($arr[$keys[5]]);
1215
        }
1216
        if (array_key_exists($keys[6], $arr)) {
1217
            $this->setMessage($arr[$keys[6]]);
1218
        }
1219
        if (array_key_exists($keys[7], $arr)) {
1220
            $this->setStatus($arr[$keys[7]]);
1221
        }
1222
        if (array_key_exists($keys[8], $arr)) {
1223
            $this->setDatetime($arr[$keys[8]]);
1224
        }
1225
    }
1226
1227
     /**
1228
     * Populate the current object from a string, using a given parser format
1229
     * <code>
1230
     * $book = new Book();
1231
     * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}');
1232
     * </code>
1233
     *
1234
     * You can specify the key type of the array by additionally passing one
1235
     * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
1236
     * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
1237
     * The default key type is the column's TableMap::TYPE_PHPNAME.
1238
     *
1239
     * @param mixed $parser A AbstractParser instance,
1240
     *                       or a format name ('XML', 'YAML', 'JSON', 'CSV')
1241
     * @param string $data The source data to import from
1242
     * @param string $keyType The type of keys the array uses.
1243
     *
1244
     * @return $this|\eXpansion\Framework\PlayersBundle\Model\Gamecurrency The current object, for fluid interface
1245
     */
1246
    public function importFrom($parser, $data, $keyType = TableMap::TYPE_PHPNAME)
1247
    {
1248
        if (!$parser instanceof AbstractParser) {
1249
            $parser = AbstractParser::getParser($parser);
1250
        }
1251
1252
        $this->fromArray($parser->toArray($data), $keyType);
1253
1254
        return $this;
1255
    }
1256
1257
    /**
1258
     * Build a Criteria object containing the values of all modified columns in this object.
1259
     *
1260
     * @return Criteria The Criteria object containing all modified values.
1261
     */
1262
    public function buildCriteria()
1263
    {
1264
        $criteria = new Criteria(GamecurrencyTableMap::DATABASE_NAME);
1265
1266
        if ($this->isColumnModified(GamecurrencyTableMap::COL_ID)) {
1267
            $criteria->add(GamecurrencyTableMap::COL_ID, $this->id);
1268
        }
1269
        if ($this->isColumnModified(GamecurrencyTableMap::COL_SENDERLOGIN)) {
1270
            $criteria->add(GamecurrencyTableMap::COL_SENDERLOGIN, $this->senderlogin);
1271
        }
1272
        if ($this->isColumnModified(GamecurrencyTableMap::COL_RECEIVERLOGIN)) {
1273
            $criteria->add(GamecurrencyTableMap::COL_RECEIVERLOGIN, $this->receiverlogin);
1274
        }
1275
        if ($this->isColumnModified(GamecurrencyTableMap::COL_TRANSACTIONID)) {
1276
            $criteria->add(GamecurrencyTableMap::COL_TRANSACTIONID, $this->transactionid);
1277
        }
1278
        if ($this->isColumnModified(GamecurrencyTableMap::COL_BILLID)) {
1279
            $criteria->add(GamecurrencyTableMap::COL_BILLID, $this->billid);
1280
        }
1281
        if ($this->isColumnModified(GamecurrencyTableMap::COL_AMOUNT)) {
1282
            $criteria->add(GamecurrencyTableMap::COL_AMOUNT, $this->amount);
1283
        }
1284
        if ($this->isColumnModified(GamecurrencyTableMap::COL_MESSAGE)) {
1285
            $criteria->add(GamecurrencyTableMap::COL_MESSAGE, $this->message);
1286
        }
1287
        if ($this->isColumnModified(GamecurrencyTableMap::COL_STATUS)) {
1288
            $criteria->add(GamecurrencyTableMap::COL_STATUS, $this->status);
1289
        }
1290
        if ($this->isColumnModified(GamecurrencyTableMap::COL_DATETIME)) {
1291
            $criteria->add(GamecurrencyTableMap::COL_DATETIME, $this->datetime);
1292
        }
1293
1294
        return $criteria;
1295
    }
1296
1297
    /**
1298
     * Builds a Criteria object containing the primary key for this object.
1299
     *
1300
     * Unlike buildCriteria() this method includes the primary key values regardless
1301
     * of whether or not they have been modified.
1302
     *
1303
     * @throws LogicException if no primary key is defined
1304
     *
1305
     * @return Criteria The Criteria object containing value(s) for primary key(s).
1306
     */
1307
    public function buildPkeyCriteria()
1308
    {
1309
        $criteria = ChildGamecurrencyQuery::create();
1310
        $criteria->add(GamecurrencyTableMap::COL_ID, $this->id);
1311
1312
        return $criteria;
1313
    }
1314
1315
    /**
1316
     * If the primary key is not null, return the hashcode of the
1317
     * primary key. Otherwise, return the hash code of the object.
1318
     *
1319
     * @return int Hashcode
1320
     */
1321
    public function hashCode()
1322
    {
1323
        $validPk = null !== $this->getId();
1324
1325
        $validPrimaryKeyFKs = 0;
1326
        $primaryKeyFKs = [];
1327
1328
        if ($validPk) {
1329
            return crc32(json_encode($this->getPrimaryKey(), JSON_UNESCAPED_UNICODE));
1330
        } elseif ($validPrimaryKeyFKs) {
1331
            return crc32(json_encode($primaryKeyFKs, JSON_UNESCAPED_UNICODE));
1332
        }
1333
1334
        return spl_object_hash($this);
1335
    }
1336
1337
    /**
1338
     * Returns the primary key for this object (row).
1339
     * @return int
1340
     */
1341
    public function getPrimaryKey()
1342
    {
1343
        return $this->getId();
1344
    }
1345
1346
    /**
1347
     * Generic method to set the primary key (id column).
1348
     *
1349
     * @param       int $key Primary key.
1350
     * @return void
1351
     */
1352
    public function setPrimaryKey($key)
1353
    {
1354
        $this->setId($key);
1355
    }
1356
1357
    /**
1358
     * Returns true if the primary key for this object is null.
1359
     * @return boolean
1360
     */
1361
    public function isPrimaryKeyNull()
1362
    {
1363
        return null === $this->getId();
1364
    }
1365
1366
    /**
1367
     * Sets contents of passed object to values from current object.
1368
     *
1369
     * If desired, this method can also make copies of all associated (fkey referrers)
1370
     * objects.
1371
     *
1372
     * @param      object $copyObj An object of \eXpansion\Framework\PlayersBundle\Model\Gamecurrency (or compatible) type.
1373
     * @param      boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1374
     * @param      boolean $makeNew Whether to reset autoincrement PKs and make the object new.
1375
     * @throws PropelException
1376
     */
1377
    public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
0 ignored issues
show
Unused Code introduced by
The parameter $deepCopy is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1378
    {
1379
        $copyObj->setSenderlogin($this->getSenderlogin());
1380
        $copyObj->setReceiverlogin($this->getReceiverlogin());
1381
        $copyObj->setTransactionid($this->getTransactionid());
1382
        $copyObj->setBillid($this->getBillid());
1383
        $copyObj->setAmount($this->getAmount());
1384
        $copyObj->setMessage($this->getMessage());
1385
        $copyObj->setStatus($this->getStatus());
1386
        $copyObj->setDatetime($this->getDatetime());
1387
        if ($makeNew) {
1388
            $copyObj->setNew(true);
1389
            $copyObj->setId(NULL); // this is a auto-increment column, so set to default value
1390
        }
1391
    }
1392
1393
    /**
1394
     * Makes a copy of this object that will be inserted as a new row in table when saved.
1395
     * It creates a new object filling in the simple attributes, but skipping any primary
1396
     * keys that are defined for the table.
1397
     *
1398
     * If desired, this method can also make copies of all associated (fkey referrers)
1399
     * objects.
1400
     *
1401
     * @param  boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1402
     * @return \eXpansion\Framework\PlayersBundle\Model\Gamecurrency Clone of current object.
1403
     * @throws PropelException
1404
     */
1405
    public function copy($deepCopy = false)
1406
    {
1407
        // we use get_class(), because this might be a subclass
1408
        $clazz = get_class($this);
1409
        $copyObj = new $clazz();
1410
        $this->copyInto($copyObj, $deepCopy);
1411
1412
        return $copyObj;
1413
    }
1414
1415
    /**
1416
     * Clears the current object, sets all attributes to their default values and removes
1417
     * outgoing references as well as back-references (from other objects to this one. Results probably in a database
1418
     * change of those foreign objects when you call `save` there).
1419
     */
1420
    public function clear()
1421
    {
1422
        $this->id = null;
1423
        $this->senderlogin = null;
1424
        $this->receiverlogin = null;
1425
        $this->transactionid = null;
1426
        $this->billid = null;
1427
        $this->amount = null;
1428
        $this->message = null;
1429
        $this->status = null;
1430
        $this->datetime = null;
1431
        $this->alreadyInSave = false;
1432
        $this->clearAllReferences();
0 ignored issues
show
Unused Code introduced by
The call to the method eXpansion\Framework\Play...y::clearAllReferences() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
1433
        $this->resetModified();
1434
        $this->setNew(true);
1435
        $this->setDeleted(false);
1436
    }
1437
1438
    /**
1439
     * Resets all references and back-references to other model objects or collections of model objects.
1440
     *
1441
     * This method is used to reset all php object references (not the actual reference in the database).
1442
     * Necessary for object serialisation.
1443
     *
1444
     * @param      boolean $deep Whether to also clear the references on all referrer objects.
1445
     */
1446
    public function clearAllReferences($deep = false)
1447
    {
1448
        if ($deep) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
1449
        } // if ($deep)
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...
1450
1451
    }
1452
1453
    /**
1454
     * Return the string representation of this object
1455
     *
1456
     * @return string The value of the 'senderLogin' column
1457
     */
1458
    public function __toString()
1459
    {
1460
        return (string) $this->getSenderlogin();
1461
    }
1462
1463
    /**
1464
     * Code to be run before persisting the object
1465
     * @param  ConnectionInterface $con
1466
     * @return boolean
1467
     */
1468
    public function preSave(ConnectionInterface $con = null)
1469
    {
1470
        if (is_callable('parent::preSave')) {
1471
            return parent::preSave($con);
1472
        }
1473
        return true;
1474
    }
1475
1476
    /**
1477
     * Code to be run after persisting the object
1478
     * @param ConnectionInterface $con
1479
     */
1480
    public function postSave(ConnectionInterface $con = null)
1481
    {
1482
        if (is_callable('parent::postSave')) {
1483
            parent::postSave($con);
1484
        }
1485
    }
1486
1487
    /**
1488
     * Code to be run before inserting to database
1489
     * @param  ConnectionInterface $con
1490
     * @return boolean
1491
     */
1492
    public function preInsert(ConnectionInterface $con = null)
1493
    {
1494
        if (is_callable('parent::preInsert')) {
1495
            return parent::preInsert($con);
1496
        }
1497
        return true;
1498
    }
1499
1500
    /**
1501
     * Code to be run after inserting to database
1502
     * @param ConnectionInterface $con
1503
     */
1504
    public function postInsert(ConnectionInterface $con = null)
1505
    {
1506
        if (is_callable('parent::postInsert')) {
1507
            parent::postInsert($con);
1508
        }
1509
    }
1510
1511
    /**
1512
     * Code to be run before updating the object in database
1513
     * @param  ConnectionInterface $con
1514
     * @return boolean
1515
     */
1516
    public function preUpdate(ConnectionInterface $con = null)
1517
    {
1518
        if (is_callable('parent::preUpdate')) {
1519
            return parent::preUpdate($con);
1520
        }
1521
        return true;
1522
    }
1523
1524
    /**
1525
     * Code to be run after updating the object in database
1526
     * @param ConnectionInterface $con
1527
     */
1528
    public function postUpdate(ConnectionInterface $con = null)
1529
    {
1530
        if (is_callable('parent::postUpdate')) {
1531
            parent::postUpdate($con);
1532
        }
1533
    }
1534
1535
    /**
1536
     * Code to be run before deleting the object in database
1537
     * @param  ConnectionInterface $con
1538
     * @return boolean
1539
     */
1540
    public function preDelete(ConnectionInterface $con = null)
1541
    {
1542
        if (is_callable('parent::preDelete')) {
1543
            return parent::preDelete($con);
1544
        }
1545
        return true;
1546
    }
1547
1548
    /**
1549
     * Code to be run after deleting the object in database
1550
     * @param ConnectionInterface $con
1551
     */
1552
    public function postDelete(ConnectionInterface $con = null)
1553
    {
1554
        if (is_callable('parent::postDelete')) {
1555
            parent::postDelete($con);
1556
        }
1557
    }
1558
1559
1560
    /**
1561
     * Derived method to catches calls to undefined methods.
1562
     *
1563
     * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.).
1564
     * Allows to define default __call() behavior if you overwrite __call()
1565
     *
1566
     * @param string $name
1567
     * @param mixed  $params
1568
     *
1569
     * @return array|string
1570
     */
1571
    public function __call($name, $params)
1572
    {
1573
        if (0 === strpos($name, 'get')) {
1574
            $virtualColumn = substr($name, 3);
1575
            if ($this->hasVirtualColumn($virtualColumn)) {
1576
                return $this->getVirtualColumn($virtualColumn);
1577
            }
1578
1579
            $virtualColumn = lcfirst($virtualColumn);
1580
            if ($this->hasVirtualColumn($virtualColumn)) {
1581
                return $this->getVirtualColumn($virtualColumn);
1582
            }
1583
        }
1584
1585
        if (0 === strpos($name, 'from')) {
1586
            $format = substr($name, 4);
1587
1588
            return $this->importFrom($format, reset($params));
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->importFrom...ormat, reset($params)); (eXpansion\Framework\Play...Model\Base\Gamecurrency) is incompatible with the return type documented by eXpansion\Framework\Play...se\Gamecurrency::__call of type array|string.

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...
1589
        }
1590
1591
        if (0 === strpos($name, 'to')) {
1592
            $format = substr($name, 2);
1593
            $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true;
1594
1595
            return $this->exportTo($format, $includeLazyLoadColumns);
1596
        }
1597
1598
        throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name));
1599
    }
1600
1601
}
1602