Conditions | 2 |
Paths | 2 |
Total Lines | 74 |
Code Lines | 59 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
23 | public static function setUpBeforeClass() |
||
24 | { |
||
25 | $adminConn = self::getAdminConnection(); |
||
26 | $adminConn->getSchemaManager()->dropAndCreateDatabase($GLOBALS['db_name']); |
||
27 | |||
28 | $dbConnection = self::getConnection(); |
||
29 | $dbalSchema = $dbConnection->getSchemaManager()->createSchema(); |
||
30 | $namingStrategy = new DefaultNamingStrategy(); |
||
31 | |||
32 | $db = new FluidSchema($dbalSchema, $namingStrategy); |
||
33 | $fromSchema = clone $dbalSchema; |
||
34 | |||
35 | $persons = $db->table("persons") |
||
|
|||
36 | ->id() |
||
37 | ->column("email")->string(50)->unique() |
||
38 | ->column("password")->string(100)->then() |
||
39 | ->timestamps(); |
||
40 | |||
41 | $users = $db->table("users") |
||
42 | ->extends("persons") |
||
43 | ->column("lastname")->string(50) |
||
44 | ->column("firstname")->string(50) |
||
45 | ->column("password")->string(200) |
||
46 | ->column("uuid")->guid()->null() |
||
47 | ->column("parent_id")->references("users") |
||
48 | ->column("birth_date")->date() |
||
49 | ->column("access_level")->smallInt() |
||
50 | ->column("last_access")->datetime(); |
||
51 | |||
52 | |||
53 | $roles = $db->table("roles") |
||
54 | ->id() |
||
55 | ->column("label")->string(20); |
||
56 | |||
57 | $db->junctionTable("users", "roles"); |
||
58 | $usersRolesTableName = $namingStrategy->getJointureTableName("users", "roles"); |
||
59 | |||
60 | $countries = $db->table("countries") |
||
61 | ->id() |
||
62 | ->column("name")->string(100) |
||
63 | ->column("population")->bigInt() |
||
64 | ->column("birthrate")->float() |
||
65 | ->column("president_id")->references("persons") |
||
66 | ->column("population_density")->decimal(10,2) |
||
67 | ->column("summary")->text(); |
||
68 | |||
69 | $users->column("country_id")->references("countries"); |
||
70 | |||
71 | $regions = $db->table("regions") |
||
72 | ->id() |
||
73 | ->column("country_id")->references("countries") |
||
74 | ->column("name")->string("50") |
||
75 | ->column("is_active")->boolean() |
||
76 | ->column("binary")->binary() |
||
77 | ->column("datetimeTz")->datetimeTz() |
||
78 | ->column("time")->time() |
||
79 | ->column("dateImmutable")->dateImmutable() |
||
80 | ->column("datetimeImmutable")->datetimeImmutable() |
||
81 | ->column("datetimeTzImmutable")->datetimeTzImmutable() |
||
82 | ->column("timeImmutable")->timeImmutable() |
||
83 | ->column("dateInterval")->dateInterval() |
||
84 | ->column("blob")->blob() |
||
85 | ->column("array")->array() |
||
86 | ->column("json")->json() |
||
87 | ->column("jsonArray")->jsonArray() |
||
88 | ->column("object")->object(); |
||
89 | |||
90 | $sqlStmts = $dbalSchema->getMigrateFromSql($fromSchema, $dbConnection->getDatabasePlatform()); |
||
91 | foreach ($sqlStmts as $sqlStmt) { |
||
92 | $dbConnection->exec($sqlStmt); |
||
93 | } |
||
94 | |||
95 | $dbConnection->insert("roles", ["label" => "ADMIN"]); |
||
96 | $dbConnection->insert("roles", ["label" => "SIMPLE USER"]); |
||
97 | |||
191 |