Issues (20)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Database/Table.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Taisiya\PropelBundle\Database;
4
5
use Taisiya\PropelBundle\Database\Exception\InvalidArgumentException;
6
7
abstract class Table implements TableInterface
8
{
9
    const TREE_MODE_NESTED_SET        = 'nested_set';
10
    const TREE_MODE_MATERIALIZED_PATH = 'materialized_path';
11
12
    /**
13
     * @var array
14
     */
15
    private $columns = [];
16
17
    /**
18
     * @var array
19
     */
20
    private $foreignKeys = [];
21
22
    /**
23
     * @var array
24
     */
25
    private $indexes = [];
26
27
    /**
28
     * @var array
29
     */
30
    private $uniques = [];
31
32
    /**
33
     * The id method to use for auto-increment columns.
34
     *
35
     * @var string
36
     */
37
    private $idMethod = Database::ID_METHOD_NATIVE;
38
39
    /**
40
     * Object model class name. By default,
41
     * Propel uses a CamelCase version of the table name as phpName.
42
     *
43
     * @var string|null
44
     */
45
    private $phpName = null;
46
47
    /**
48
     * The “package” for the generated classes.
49
     * Classes are created in subdirectories according to the package value.
50
     *
51
     * @var string|null
52
     */
53
    private $package = null;
54
55
    /**
56
     * The default SQL schema containing the tables.
57
     * Ignored on RDBMS not supporting database schemas.
58
     *
59
     * @var string|null
60
     */
61
    private $schema = null;
62
63
    /**
64
     * The namespace that the generated model classes will use (PHP 5.3 only).
65
     * If the table namespace starts with a \\, it overrides the namespace
66
     * defined in the <database> tag; otherwise, the actual table namespace
67
     * is the concatenation of the database namespace and the table namespace.
68
     *
69
     * @var string|null
70
     */
71
    private $namespace = null;
72
73
    /**
74
     * Instructs Propel not to generate DDL SQL for the specified table.
75
     * This can be used together with readOnly for supporting VIEWS in Propel.
76
     *
77
     * @var bool
78
     */
79
    private $skipSql = false;
80
81
    /**
82
     * Whether the generated stub class will be abstract (e.g. if you’re using inheritance).
83
     *
84
     * @var bool
85
     */
86
    private $abstract = false;
87
88
    /**
89
     * The default naming method to use for tables of this database.
90
     * Defaults to underscore, which transforms table names into CamelCase phpNames.
91
     *
92
     * @var string
93
     */
94
    private $phpNamingMethod = Database::PHP_NAMING_METHOD_UNDERSCORE;
95
96
    /**
97
     * Allows you to specify a class that the generated Propel objects should extend
98
     * (in place of propel.om.BaseObject).
99
     *
100
     * @var string|null
101
     */
102
    private $baseClass = null;
103
104
    /**
105
     * A text description of the table.
106
     *
107
     * @var string|null
108
     */
109
    private $description = null;
110
111
    /**
112
     * Adds indexes for each component of the primary key (when using composite primary keys).
113
     *
114
     * @var bool
115
     */
116
    private $heavyIndexing = false;
117
118
    /**
119
     * Auotes all identifiers (table name, column names) in DDL and SQL queries.
120
     * This is necessary if you use reserved words as table or column name.
121
     *
122
     * @var bool
123
     */
124
    private $identifierQuoting = false;
125
126
    /**
127
     * Suppresses the mutator/setter methods, save() and delete() methods.
128
     *
129
     * @var bool
130
     */
131
    private $readOnly = false;
132
133
    /**
134
     * Is used to indicate that this table is part of a node tree.
135
     * Currently the only supported values are NestedSet (see the NestedSet behavior section)
136
     * and MaterializedPath (deprecated).
137
     *
138
     * @var string|null
139
     */
140
    private $treeMode = null;
141
142
    /**
143
     * Is used to indicate that the object should be reloaded from the database
144
     * when an INSERT is performed. This is useful if you have triggers
145
     * (or other server-side functionality like column default expressions)
146
     * that alters the database row on INSERT.
147
     *
148
     * @var bool
149
     */
150
    private $reloadOnInsert = true;
151
152
    /**
153
     * Is used to indicate that the object should be reloaded from the database
154
     * when an UPDATE is performed. This is useful if you have triggers
155
     * (or other server-side functionality like column default expressions)
156
     * that alters the database row on UPDATE.
157
     *
158
     * @var bool
159
     */
160
    private $reloadOnUpdate = true;
161
162
    /**
163
     * Can be used if you want to define the primary key of a new object being inserted.
164
     * By default if idMethod is “native”, Propel would throw an exception.
165
     * However, in some cases this feature is useful, for example if you do some replication
166
     * of data in an master-master environment. It defaults to false.
167
     *
168
     * @var bool
169
     */
170
    private $allowPkInsert = false;
171
172
    /**
173
     * @return string
174
     */
175
    final public function getIdMethod(): string
176
    {
177
        return $this->idMethod;
178
    }
179
180
    /**
181
     * @param string $idMethod
182
     *
183
     * @throws InvalidArgumentException
184
     *
185
     * @return Table
186
     */
187
    final public function setIdMethod(string $idMethod): Table
188
    {
189
        $available = [
190
            Database::ID_METHOD_NATIVE,
191
            Database::ID_METHOD_NONE,
192
        ];
193
194
        if (!in_array($idMethod, $available)) {
195
            throw new InvalidArgumentException('Invalid idMethod value');
196
        }
197
198
        $this->idMethod = $idMethod;
199
200
        return $this;
201
    }
202
203
    /**
204
     * @return string|null
205
     */
206
    final public function getPhpName(): ? string
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected '?'
Loading history...
207
    {
208
        return $this->phpName;
209
    }
210
211
    /**
212
     * @param string|null $phpName
213
     *
214
     * @return Database
215
     */
216
    final public function setPhpName(string $phpName = null)
217
    {
218
        $this->phpName = $phpName;
219
220
        return $this;
221
    }
222
223
    /**
224
     * @param Column $column
225
     *
226
     * @throws InvalidArgumentException
227
     *
228
     * @return Table
229
     */
230
    final public function createColumn(Column $column) : Table
231
    {
232
        if ($this->hasColumn($column::getName())) {
233
            throw new InvalidArgumentException('Column '.$column::getName().' already added');
234
        }
235
236
        $this->columns[$column::getName()] = $column;
237
238
        return $this;
239
    }
240
241
    /**
242
     * @param Column $column
243
     *
244
     * @return Table
245
     */
246
    final public function createColumnIfNotExists(Column $column): Table
247
    {
248
        if (!$this->hasColumn($column::getName())) {
249
            $this->createColumn($column);
250
        }
251
252
        return $this;
253
    }
254
255
    /**
256
     * @param Column $column
257
     *
258
     * @throws InvalidArgumentException
259
     *
260
     * @return Table
261
     */
262
    final public function removeColumn(Column $column): Table
263
    {
264
        if (!$this->hasColumn($column::getName())) {
265
            throw new InvalidArgumentException('Column '.$column::getName().' not exists');
266
        }
267
268
        unset($this->columns[$column::getName()]);
269
270
        return $this;
271
    }
272
273
    /**
274
     * @param string $name
275
     *
276
     * @throws InvalidArgumentException
277
     *
278
     * @return Column
279
     */
280
    final public function getColumn(string $name): Column
281
    {
282
        if (!array_key_exists($name, $this->columns)) {
283
            throw new InvalidArgumentException('Column '.$name.' not added');
284
        }
285
286
        return $this->columns[$name];
287
    }
288
289
    /**
290
     * @param string $name
291
     *
292
     * @return bool
293
     */
294
    final public function hasColumn(string $name): bool
295
    {
296
        return array_key_exists($name, $this->columns);
297
    }
298
299
    /**
300
     * @return array
301
     */
302
    final public function getColumns(): array
303
    {
304
        return $this->columns;
305
    }
306
307
    /**
308
     * @return null|string
309
     */
310
    final public function getPackage(): ? string
311
    {
312
        return $this->package;
313
    }
314
315
    /**
316
     * @param null|string $package
317
     *
318
     * @return Table
319
     */
320
    final public function setPackage(string $package = null) : Table
321
    {
322
        $this->package = $package;
323
324
        return $this;
325
    }
326
327
    /**
328
     * @return null|string
329
     */
330
    final public function getSchema(): ? string
331
    {
332
        return $this->schema;
333
    }
334
335
    /**
336
     * @param null|string $schema
337
     *
338
     * @return Table
339
     */
340
    final public function setSchema(string $schema = null) : Table
341
    {
342
        $this->schema = $schema;
343
344
        return $this;
345
    }
346
347
    /**
348
     * @return null|string
349
     */
350
    final public function getNamespace(): ? string
351
    {
352
        return $this->namespace;
353
    }
354
355
    /**
356
     * @param null|string $namespace
357
     *
358
     * @return Table
359
     */
360
    final public function setNamespace(string $namespace = null) : Table
361
    {
362
        $this->namespace = $namespace;
363
364
        return $this;
365
    }
366
367
    /**
368
     * @return bool
369
     */
370
    final public function isSkipSql(): bool
371
    {
372
        return $this->skipSql;
373
    }
374
375
    /**
376
     * @param bool $skipSql
377
     *
378
     * @return Table
379
     */
380
    final public function setSkipSql(bool $skipSql): Table
381
    {
382
        $this->skipSql = $skipSql;
383
384
        return $this;
385
    }
386
387
    /**
388
     * @return bool
389
     */
390
    final public function isAbstract(): bool
391
    {
392
        return $this->abstract;
393
    }
394
395
    /**
396
     * @param bool $abstract
397
     *
398
     * @return Table
399
     */
400
    final public function setAbstract(bool $abstract): Table
401
    {
402
        $this->abstract = $abstract;
403
404
        return $this;
405
    }
406
407
    /**
408
     * @return string
409
     */
410
    final public function getPhpNamingMethod(): string
411
    {
412
        return $this->phpNamingMethod;
413
    }
414
415
    /**
416
     * @param string $phpNamingMethod
417
     *
418
     * @return Table
419
     */
420
    final public function setPhpNamingMethod(string $phpNamingMethod): Table
421
    {
422
        $availableMethods = [
423
            Database::PHP_NAMING_METHOD_NOCHANGE,
424
            Database::PHP_NAMING_METHOD_UNDERSCORE,
425
            Database::PHP_NAMING_METHOD_PHPNAME,
426
            Database::PHP_NAMING_METHOD_CLEAN,
427
        ];
428
429
        if (!in_array($phpNamingMethod, $availableMethods)) {
430
            throw new InvalidArgumentException('Invalid naming method.');
431
        }
432
433
        $this->phpNamingMethod = $phpNamingMethod;
434
435
        return $this;
436
    }
437
438
    /**
439
     * @return null|string
440
     */
441
    final public function getBaseClass(): ? string
442
    {
443
        return $this->baseClass;
444
    }
445
446
    /**
447
     * @param null|string $baseClass
448
     *
449
     * @return Table
450
     */
451
    final public function setBaseClass(string $baseClass = null) : Table
452
    {
453
        $this->baseClass = $baseClass;
454
455
        return $this;
456
    }
457
458
    /**
459
     * @return null|string
460
     */
461
    final public function getDescription(): ? string
462
    {
463
        return $this->description;
464
    }
465
466
    /**
467
     * @param null|string $description
468
     *
469
     * @return Table
470
     */
471
    final public function setDescription(string $description = null) : Table
472
    {
473
        $this->description = $description;
474
475
        return $this;
476
    }
477
478
    /**
479
     * @return bool
480
     */
481
    final public function isHeavyIndexing(): bool
482
    {
483
        return $this->heavyIndexing;
484
    }
485
486
    /**
487
     * @param bool $heavyIndexing
488
     *
489
     * @return Table
490
     */
491
    final public function setHeavyIndexing(bool $heavyIndexing): Table
492
    {
493
        $this->heavyIndexing = $heavyIndexing;
494
495
        return $this;
496
    }
497
498
    /**
499
     * @return bool
500
     */
501
    final public function isIdentifierQuoting(): bool
502
    {
503
        return $this->identifierQuoting;
504
    }
505
506
    /**
507
     * @param bool $identifierQuoting
508
     *
509
     * @return Table
510
     */
511
    final public function setIdentifierQuoting(bool $identifierQuoting): Table
512
    {
513
        $this->identifierQuoting = $identifierQuoting;
514
515
        return $this;
516
    }
517
518
    /**
519
     * @return bool
520
     */
521
    final public function isReadOnly(): bool
522
    {
523
        return $this->readOnly;
524
    }
525
526
    /**
527
     * @param bool $readOnly
528
     *
529
     * @return Table
530
     */
531
    final public function setReadOnly(bool $readOnly): Table
532
    {
533
        $this->readOnly = $readOnly;
534
535
        return $this;
536
    }
537
538
    /**
539
     * @return null|string
540
     */
541
    final public function getTreeMode(): ? string
542
    {
543
        return $this->treeMode;
544
    }
545
546
    /**
547
     * @param null|string $treeMode
548
     *
549
     * @throws InvalidArgumentException
550
     *
551
     * @return Table
552
     */
553
    final public function setTreeMode(string $treeMode = null) : Table
554
    {
555
        if ($treeMode !== null) {
556
            $available = [
557
                self::TREE_MODE_NESTED_SET,
558
                self::TREE_MODE_MATERIALIZED_PATH,
559
            ];
560
561
            if (!in_array($treeMode, $available)) {
562
                throw new InvalidArgumentException('Invalid tree mode.');
563
            }
564
        }
565
566
        $this->treeMode = $treeMode;
567
568
        return $this;
569
    }
570
571
    /**
572
     * @return bool
573
     */
574
    final public function isReloadOnInsert(): bool
575
    {
576
        return $this->reloadOnInsert;
577
    }
578
579
    /**
580
     * @param bool $reloadOnInsert
581
     *
582
     * @return Table
583
     */
584
    final public function setReloadOnInsert(bool $reloadOnInsert): Table
585
    {
586
        $this->reloadOnInsert = $reloadOnInsert;
587
588
        return $this;
589
    }
590
591
    /**
592
     * @return bool
593
     */
594
    final public function isReloadOnUpdate(): bool
595
    {
596
        return $this->reloadOnUpdate;
597
    }
598
599
    /**
600
     * @param bool $reloadOnUpdate
601
     *
602
     * @return Table
603
     */
604
    final public function setReloadOnUpdate(bool $reloadOnUpdate): Table
605
    {
606
        $this->reloadOnUpdate = $reloadOnUpdate;
607
608
        return $this;
609
    }
610
611
    /**
612
     * @return bool
613
     */
614
    final public function isAllowPkInsert(): bool
615
    {
616
        return $this->allowPkInsert;
617
    }
618
619
    /**
620
     * @param bool $allowPkInsert
621
     *
622
     * @return Table
623
     */
624
    final public function setAllowPkInsert(bool $allowPkInsert): Table
625
    {
626
        $this->allowPkInsert = $allowPkInsert;
627
628
        return $this;
629
    }
630
631
    /**
632
     * @return array
633
     */
634
    final public function getForeignKeys(): array
635
    {
636
        return $this->foreignKeys;
637
    }
638
639
    /**
640
     * @param string $name
641
     *
642
     * @return ForeignKey
643
     */
644
    final public function getForeignKey(string $name): ForeignKey
645
    {
646
        return $this->foreignKeys[$name];
647
    }
648
649
    /**
650
     * @param string $name
651
     *
652
     * @return bool
653
     */
654
    final public function hasForeignKey(string $name): bool
655
    {
656
        return array_key_exists($name, $this->foreignKeys);
657
    }
658
659
    /**
660
     * @param ForeignKey $foreignKey
661
     *
662
     * @return Table
663
     */
664
    final public function addForeignKey(ForeignKey $foreignKey): Table
665
    {
666
        if ($this->hasForeignKey($foreignKey::getName())) {
667
            throw new InvalidArgumentException('Foreign key '.$foreignKey::getName().' already exists in the table '.$this::getName());
668
        }
669
670
        $this->foreignKeys[$foreignKey::getName()] = $foreignKey;
671
672
        return $this;
673
    }
674
675
    /**
676
     * @param ForeignKey $foreignKey
677
     *
678
     * @return Table
679
     */
680
    final public function removeForeignKey(ForeignKey $foreignKey): Table
681
    {
682
        if (!$this->hasForeignKey($foreignKey::getName())) {
683
            throw new InvalidArgumentException('Foreign key '.$foreignKey::getName().' not exists in the table '.$this::getName());
684
        }
685
686
        unset($this->foreignKeys[$foreignKey::getName()]);
687
688
        return $this;
689
    }
690
691
    /**
692
     * @return array
693
     */
694
    final public function getIndexes(): array
695
    {
696
        return $this->indexes;
697
    }
698
699
    /**
700
     * @param string $name
701
     *
702
     * @return Index
703
     */
704
    final public function getIndex(string $name): Index
705
    {
706
        return $this->indexes[$name];
707
    }
708
709
    /**
710
     * @param string $name
711
     *
712
     * @return bool
713
     */
714
    final public function hasIndex(string $name): bool
715
    {
716
        return array_key_exists($name, $this->indexes);
717
    }
718
719
    /**
720
     * @param Index $index
721
     *
722
     * @return Table
723
     */
724
    final public function addIndex(Index $index): Table
725
    {
726
        if ($this->hasIndex($index::getName())) {
727
            throw new InvalidArgumentException('Foreign key '.$index::getName().' already exists in the table '.$this::getName());
728
        }
729
730
        $this->indexes[$index::getName()] = $index;
731
732
        return $this;
733
    }
734
735
    /**
736
     * @param Index $index
737
     *
738
     * @return Table
739
     */
740
    final public function removeIndex(Index $index): Table
741
    {
742
        if (!$this->hasIndex($index::getName())) {
743
            throw new InvalidArgumentException('Foreign key '.$index::getName().' not exists in the table '.$this::getName());
744
        }
745
746
        unset($this->indexes[$index::getName()]);
747
748
        return $this;
749
    }
750
751
    /**
752
     * @return array
753
     */
754
    final public function getUniques(): array
755
    {
756
        return $this->uniques;
757
    }
758
759
    /**
760
     * @param string $name
761
     *
762
     * @return Unique
763
     */
764
    final public function getUnique(string $name): Unique
765
    {
766
        return $this->uniques[$name];
767
    }
768
769
    /**
770
     * @param string $name
771
     *
772
     * @return bool
773
     */
774
    final public function hasUnique(string $name): bool
775
    {
776
        return array_key_exists($name, $this->uniques);
777
    }
778
779
    /**
780
     * @param Unique $index
781
     *
782
     * @return Table
783
     */
784
    final public function addUnique(Unique $index): Table
785
    {
786
        if ($this->hasUnique($index::getName())) {
787
            throw new InvalidArgumentException('Foreign key '.$index::getName().' already exists in the table '.$this::getName());
788
        }
789
790
        $this->uniques[$index::getName()] = $index;
791
792
        return $this;
793
    }
794
795
    /**
796
     * @param Unique $index
797
     *
798
     * @return Table
799
     */
800
    final public function removeUnique(Unique $index): Table
801
    {
802
        if (!$this->hasUnique($index::getName())) {
803
            throw new InvalidArgumentException('Foreign key '.$index::getName().' not exists in the table '.$this::getName());
804
        }
805
806
        unset($this->uniques[$index::getName()]);
807
808
        return $this;
809
    }
810
811
    /**
812
     * @param \DOMDocument $dom
813
     * @param \DOMElement  $database
814
     */
815
    final public function appendToXmlDocument(\DOMDocument $dom, \DOMElement $database): void
816
    {
817
        $table = $dom->createElement('table');
818
        $table->setAttribute('name', $this::getName());
819
820
        $additionalProperties = [
821
            'idMethod',
822
            'phpName',
823
            'package',
824
            'schema',
825
            'namespace',
826
            'skipSql',
827
            'abstract',
828
            'phpNamingMethod',
829
            'baseClass',
830
            'description',
831
            'heavyIndexing',
832
            'identifierQuoting',
833
            'readOnly',
834
            'treeMode',
835
            'reloadOnInsert',
836
            'reloadOnUpdate',
837
            'allowPkInsert',
838
        ];
839
840
        foreach ($additionalProperties as $propertyName) {
841
            $method = method_exists($this, 'get'.ucfirst($propertyName))
842
                ? 'get'.ucfirst($propertyName)
843
                : 'is'.ucfirst($propertyName);
844
845
            $propertyValue = $this->{$method}();
846
            if ($propertyValue != '') {
847
                if (is_bool($propertyValue)) {
848
                    $propertyValue = $propertyValue ? 'true' : false;
849
                }
850
                $table->setAttribute($propertyName, $propertyValue);
851
            }
852
        }
853
854
        /** @var Column $column */
855
        foreach ($this->getColumns() as $column) {
856
            $column->appendToXmlDocument($dom, $table);
857
        }
858
859
        /** @var Index $index */
860
        foreach ($this->getIndexes() as $index) {
861
            $index->appendToXmlDocument($dom, $table);
862
        }
863
864
        /** @var uniqueIndex $uniqueIndex */
865
        foreach ($this->getUniques() as $uniqueIndex) {
866
            $uniqueIndex->appendToXmlDocument($dom, $table);
867
        }
868
869
        $database->appendChild($table);
870
    }
871
}
872