• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

thecodingmachine / dbal-fluid-schema-builder / 7686160655

28 Jan 2024 01:42PM UTC coverage: 100.0% (+0.6%) from 99.415%
7686160655

push

github

web-flow
Merge pull request #13 from aszenz/master

ci: Improve tests + fix ci deps

171 of 171 relevant lines covered (100.0%)

14.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/DefaultNamingStrategy.php
1
<?php
2

3

4
namespace TheCodingMachine\FluidSchema;
5

6
use Doctrine\DBAL\Platforms\AbstractPlatform;
7
use Doctrine\Inflector\Inflector;
8
use Doctrine\Inflector\InflectorFactory;
9

10
class DefaultNamingStrategy implements NamingStrategyInterface
11
{
12
    /**
13
     * @var AbstractPlatform
14
     */
15
    private $platform;
16
    /**
17
     * @var Inflector
18
     */
19
    private $inflector;
20

21
    public function __construct(AbstractPlatform $platform = null)
22
    {
23
        $this->platform = $platform;
69✔
24
        $this->inflector = InflectorFactory::create()->build();
69✔
25
    }
26

27
    /**
28
     * Returns the name of the jointure table from the name of the joined tables.
29
     *
30
     * @param string $table1
31
     * @param string $table2
32
     * @return string
33
     */
34
    public function getJointureTableName(string $table1, string $table2): string
35
    {
36
        return $table1.'_'.$table2;
6✔
37
    }
38

39
    /**
40
     * Returns the name of a foreign key column based on the name of the targeted table.
41
     *
42
     * @param string $targetTable
43
     * @return string
44
     */
45
    public function getForeignKeyColumnName(string $targetTable): string
46
    {
47
        return $this->toSingular($targetTable).'_id';
6✔
48
    }
49

50
    /**
51
     * Put all the words of a string separated by underscores on singular.
52
     * Assumes the words are in English and in their plural form.
53
     *
54
     * @param $plural
55
     * @return string
56
     */
57
    private function toSingular($plural): string
58
    {
59
        $tokens = preg_split("/[_ ]+/", $plural);
6✔
60

61
        $strs = [];
6✔
62
        foreach ($tokens as $token) {
6✔
63
            $strs[] = $this->inflector->singularize($token);
6✔
64
        }
65

66
        return implode('_', $strs);
6✔
67
    }
68

69
    /**
70
     * Let's quote if a database platform has been provided to us!
71
     *
72
     * @param string $identifier
73
     * @return string
74
     */
75
    public function quoteIdentifier(string $identifier): string
76
    {
77
        return ($this->platform !== null) ? $this->platform->quoteIdentifier($identifier) : $identifier;
60✔
78
    }
79
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc