| Conditions | 7 |
| Paths | 8 |
| Total Lines | 79 |
| Code Lines | 49 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 55 | public function wire(ContainerInterface $dic) |
||
| 56 | { |
||
| 57 | if (empty($dic['Yapeal.Sql.CommonQueries'])) { |
||
| 58 | $dic['Yapeal.Sql.CommonQueries'] = function ($dic) { |
||
| 59 | return new $dic['Yapeal.Sql.sharedSql']( |
||
| 60 | $dic['Yapeal.Sql.database'], $dic['Yapeal.Sql.tablePrefix'] |
||
| 61 | ); |
||
| 62 | }; |
||
| 63 | } |
||
| 64 | if (!empty($dic['Yapeal.Sql.Connection'])) { |
||
| 65 | return $this; |
||
| 66 | } |
||
| 67 | if ('mysql' !== $dic['Yapeal.Sql.platform']) { |
||
| 68 | $mess = 'Unknown platform, was given ' . $dic['Yapeal.Sql.platform']; |
||
| 69 | throw new YapealDatabaseException($mess); |
||
| 70 | } |
||
| 71 | $dic['Yapeal.Sql.Connection'] = function ($dic) { |
||
| 72 | $dsn = $dic['Yapeal.Sql.platform'] . ':host=' . $dic['Yapeal.Sql.hostName'] . ';charset=utf8'; |
||
| 73 | if (!empty($dic['Yapeal.Sql.port'])) { |
||
| 74 | $dsn .= ';port=' . $dic['Yapeal.Sql.port']; |
||
| 75 | } |
||
| 76 | /** |
||
| 77 | * @var PDO $database |
||
| 78 | */ |
||
| 79 | $database = new $dic['Yapeal.Sql.class']( |
||
| 80 | $dsn, $dic['Yapeal.Sql.userName'], $dic['Yapeal.Sql.password'] |
||
| 81 | ); |
||
| 82 | $database->setAttribute( |
||
| 83 | PDO::ATTR_ERRMODE, |
||
| 84 | PDO::ERRMODE_EXCEPTION |
||
| 85 | ); |
||
| 86 | $database->exec('SET SESSION SQL_MODE=\'ANSI,TRADITIONAL\''); |
||
| 87 | $database->exec('SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE'); |
||
| 88 | $database->exec('SET SESSION TIME_ZONE=\'+00:00\''); |
||
| 89 | $database->exec('SET NAMES utf8mb4 COLLATE utf8mb4_unicode_520_ci'); |
||
| 90 | $database->exec('SET COLLATION_CONNECTION=utf8mb4_unicode_520_ci'); |
||
| 91 | $database->exec('SET DEFAULT_STORAGE_ENGINE=' . $dic['Yapeal.Sql.engine']); |
||
| 92 | return $database; |
||
| 93 | }; |
||
| 94 | if (empty($dic['Yapeal.Sql.Creator'])) { |
||
| 95 | $dic['Yapeal.Sql.Creator'] = $dic->factory( |
||
| 96 | function ($dic) { |
||
| 97 | $loader = new Twig_Loader_Filesystem($dic['Yapeal.Sql.dir']); |
||
| 98 | $twig = new Twig_Environment( |
||
| 99 | $loader, ['debug' => true, 'strict_variables' => true, 'autoescape' => false] |
||
| 100 | ); |
||
| 101 | $filter = new Twig_SimpleFilter( |
||
| 102 | 'ucFirst', function ($value) { |
||
| 103 | return ucfirst($value); |
||
| 104 | } |
||
| 105 | ); |
||
| 106 | $twig->addFilter($filter); |
||
| 107 | $filter = new Twig_SimpleFilter( |
||
| 108 | 'lcFirst', function ($value) { |
||
| 109 | return lcfirst($value); |
||
| 110 | } |
||
| 111 | ); |
||
| 112 | $twig->addFilter($filter); |
||
| 113 | /** |
||
| 114 | * @var \Yapeal\Sql\Creator $create |
||
| 115 | */ |
||
| 116 | $create = new $dic['Yapeal.Sql.create']($twig, $dic['Yapeal.Sql.dir'], $dic['Yapeal.Sql.platform']); |
||
| 117 | if (array_key_exists('Yapeal.Create.overwrite', $dic)) { |
||
| 118 | $create->setOverwrite($dic['Yapeal.Create.overwrite']); |
||
| 119 | } |
||
| 120 | return $create; |
||
| 121 | } |
||
| 122 | ); |
||
| 123 | } |
||
| 124 | /** |
||
| 125 | * @var \Yapeal\Event\MediatorInterface $mediator |
||
| 126 | */ |
||
| 127 | $mediator = $dic['Yapeal.Event.Mediator']; |
||
| 128 | $mediator->addServiceSubscriberByEventList( |
||
| 129 | 'Yapeal.Sql.Creator', |
||
| 130 | ['Yapeal.EveApi.create' => ['createSql', 'last']] |
||
| 131 | ); |
||
| 132 | return $this; |
||
| 133 | } |
||
| 134 | } |
||
| 135 |