1 | <?php |
||||||
2 | |||||||
3 | namespace TheCodingMachine\TDBM\Performance; |
||||||
4 | |||||||
5 | use Doctrine\Common\Cache\ArrayCache; |
||||||
6 | use Doctrine\Common\Cache\VoidCache; |
||||||
7 | use Doctrine\DBAL\Connection; |
||||||
8 | use Mouf\Database\SchemaAnalyzer\SchemaAnalyzer; |
||||||
9 | use PhpBench\Benchmark\Metadata\Annotations\Iterations; |
||||||
10 | use TheCodingMachine\FluidSchema\TdbmFluidSchema; |
||||||
11 | use TheCodingMachine\TDBM\Configuration; |
||||||
12 | use TheCodingMachine\TDBM\ConfigurationInterface; |
||||||
13 | use TheCodingMachine\TDBM\ConnectionFactory; |
||||||
14 | use TheCodingMachine\TDBM\DummyGeneratorListener; |
||||||
15 | use TheCodingMachine\TDBM\SchemaLockFileDumper; |
||||||
16 | use TheCodingMachine\TDBM\TDBMAbstractServiceTest; |
||||||
17 | use TheCodingMachine\TDBM\TDBMSchemaAnalyzer; |
||||||
18 | use TheCodingMachine\TDBM\TDBMService; |
||||||
19 | use TheCodingMachine\TDBM\Test\Dao\UserDao; |
||||||
0 ignored issues
–
show
|
|||||||
20 | use TheCodingMachine\TDBM\Utils\PathFinder\PathFinder; |
||||||
21 | use TheCodingMachine\TDBM\Utils\TDBMDaoGenerator; |
||||||
22 | |||||||
23 | use function dirname; |
||||||
24 | use function getenv; |
||||||
25 | use function glob; |
||||||
26 | use function is_dir; |
||||||
27 | use function is_file; |
||||||
28 | use function rmdir; |
||||||
29 | use function rtrim; |
||||||
30 | use function unlink; |
||||||
31 | |||||||
32 | /** |
||||||
33 | * @BeforeClassMethods({"initDatabase"}) |
||||||
34 | */ |
||||||
35 | class ManyToOneBench |
||||||
36 | { |
||||||
37 | public static function initDatabase(): void |
||||||
38 | { |
||||||
39 | $dbConnection = ConnectionFactory::resetDatabase( |
||||||
40 | getenv('DB_DRIVER') ?: null, |
||||||
0 ignored issues
–
show
It seems like
getenv('DB_DRIVER') ?: null can also be of type null ; however, parameter $dbDriver of TheCodingMachine\TDBM\Co...actory::resetDatabase() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
41 | getenv('DB_HOST') ?: null, |
||||||
42 | getenv('DB_PORT') ?: null, |
||||||
43 | getenv('DB_USERNAME') ?: null, |
||||||
44 | getenv('DB_ADMIN_USERNAME') ?: null, |
||||||
45 | getenv('DB_PASSWORD') ?: null, |
||||||
46 | getenv('DB_NAME') ?: null |
||||||
47 | ); |
||||||
48 | |||||||
49 | self::initSchema($dbConnection); |
||||||
50 | |||||||
51 | self::generateDaosAndBeans($dbConnection); |
||||||
52 | } |
||||||
53 | |||||||
54 | private static function initSchema(Connection $connection): void |
||||||
55 | { |
||||||
56 | $fromSchema = $connection->getSchemaManager()->createSchema(); |
||||||
0 ignored issues
–
show
The function
Doctrine\DBAL\Connection::getSchemaManager() has been deprecated: Use {@see createSchemaManager()} instead.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead. ![]() The function
Doctrine\DBAL\Schema\Abs...Manager::createSchema() has been deprecated: Use {@link introspectSchema()} instead.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead. ![]() |
|||||||
57 | $toSchema = clone $fromSchema; |
||||||
58 | |||||||
59 | $db = new TdbmFluidSchema($toSchema, new \TheCodingMachine\FluidSchema\DefaultNamingStrategy($connection->getDatabasePlatform())); |
||||||
60 | |||||||
61 | $db->table('countries') |
||||||
62 | ->column('id')->integer()->primaryKey() |
||||||
63 | ->column('label')->string(255)->unique(); |
||||||
64 | |||||||
65 | $db->table('users') |
||||||
66 | ->column('id')->integer()->primaryKey() |
||||||
67 | ->column('name')->string(255) |
||||||
68 | ->column('country_id')->references('countries'); |
||||||
69 | |||||||
70 | $sqlStmts = $toSchema->getMigrateFromSql($fromSchema, $connection->getDatabasePlatform()); |
||||||
0 ignored issues
–
show
The function
Doctrine\DBAL\Schema\Schema::getMigrateFromSql() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
71 | |||||||
72 | foreach ($sqlStmts as $sqlStmt) { |
||||||
73 | $connection->exec($sqlStmt); |
||||||
0 ignored issues
–
show
The function
Doctrine\DBAL\Connection::exec() has been deprecated: please use {@see executeStatement()} instead
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead. ![]() |
|||||||
74 | } |
||||||
75 | |||||||
76 | for ($i = 1; $i < 200; $i++) { |
||||||
77 | TDBMAbstractServiceTest::insert($connection, 'countries', [ |
||||||
78 | 'id' => $i, |
||||||
79 | 'label' => 'Country '.$i, |
||||||
80 | ]); |
||||||
81 | } |
||||||
82 | |||||||
83 | for ($i = 1; $i < 1000; $i++) { |
||||||
84 | TDBMAbstractServiceTest::insert($connection, 'users', [ |
||||||
85 | 'id' => $i, |
||||||
86 | 'name' => 'User '.$i, |
||||||
87 | 'country_id' => ($i % 199) + 1, |
||||||
88 | ]); |
||||||
89 | } |
||||||
90 | } |
||||||
91 | |||||||
92 | private static function generateDaosAndBeans(Connection $connection): void |
||||||
93 | { |
||||||
94 | $schemaManager = $connection->getSchemaManager(); |
||||||
0 ignored issues
–
show
The function
Doctrine\DBAL\Connection::getSchemaManager() has been deprecated: Use {@see createSchemaManager()} instead.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead. ![]() |
|||||||
95 | $schemaAnalyzer = new SchemaAnalyzer($schemaManager); |
||||||
96 | $schemaLockFileDumper = new SchemaLockFileDumper($connection, new ArrayCache(), Configuration::getDefaultLockFilePath()); |
||||||
0 ignored issues
–
show
The class
Doctrine\Common\Cache\ArrayCache has been deprecated: Deprecated without replacement in doctrine/cache 1.11. This class will be dropped in 2.0
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
97 | $tdbmSchemaAnalyzer = new TDBMSchemaAnalyzer($connection, new ArrayCache(), $schemaAnalyzer, $schemaLockFileDumper); |
||||||
0 ignored issues
–
show
The class
Doctrine\Common\Cache\ArrayCache has been deprecated: Deprecated without replacement in doctrine/cache 1.11. This class will be dropped in 2.0
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
98 | $tdbmDaoGenerator = new TDBMDaoGenerator(self::createConfiguration(), $tdbmSchemaAnalyzer); |
||||||
99 | $rootPath = __DIR__ . '/../'; |
||||||
0 ignored issues
–
show
|
|||||||
100 | self::recursiveDelete(__DIR__. '/../../src/Test/Dao/'); |
||||||
101 | |||||||
102 | $tdbmDaoGenerator->generateAllDaosAndBeans(); |
||||||
103 | } |
||||||
104 | |||||||
105 | /** |
||||||
106 | * Delete a file or recursively delete a directory. |
||||||
107 | * |
||||||
108 | * @param string $str Path to file or directory |
||||||
109 | * @return bool |
||||||
110 | */ |
||||||
111 | private static function recursiveDelete(string $str): bool |
||||||
112 | { |
||||||
113 | if (is_file($str)) { |
||||||
114 | return @unlink($str); |
||||||
115 | } elseif (is_dir($str)) { |
||||||
116 | $scan = glob(rtrim($str, '/') . '/*'); |
||||||
117 | foreach ($scan as $index => $path) { |
||||||
118 | self::recursiveDelete($path); |
||||||
119 | } |
||||||
120 | |||||||
121 | return @rmdir($str); |
||||||
122 | } |
||||||
123 | return false; |
||||||
124 | } |
||||||
125 | |||||||
126 | private static function getConnection(): Connection |
||||||
127 | { |
||||||
128 | return ConnectionFactory::createConnection( |
||||||
129 | getenv('DB_DRIVER') ?: null, |
||||||
0 ignored issues
–
show
It seems like
getenv('DB_DRIVER') ?: null can also be of type null ; however, parameter $dbDriver of TheCodingMachine\TDBM\Co...ory::createConnection() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
130 | getenv('DB_HOST') ?: null, |
||||||
131 | getenv('DB_PORT') ?: null, |
||||||
132 | getenv('DB_USERNAME') ?: null, |
||||||
133 | getenv('DB_PASSWORD') ?: null, |
||||||
134 | getenv('DB_NAME') ?: null |
||||||
135 | ); |
||||||
136 | } |
||||||
137 | |||||||
138 | protected function getTdbmService(): TDBMService |
||||||
139 | { |
||||||
140 | return new TDBMService($this->getConfiguration()); |
||||||
141 | } |
||||||
142 | |||||||
143 | private static $cache; |
||||||
144 | |||||||
145 | protected static function getCache(): ArrayCache |
||||||
146 | { |
||||||
147 | if (self::$cache === null) { |
||||||
148 | self::$cache = new ArrayCache(); |
||||||
0 ignored issues
–
show
The class
Doctrine\Common\Cache\ArrayCache has been deprecated: Deprecated without replacement in doctrine/cache 1.11. This class will be dropped in 2.0
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
149 | } |
||||||
150 | return self::$cache; |
||||||
151 | } |
||||||
152 | |||||||
153 | private static function createConfiguration(): ConfigurationInterface |
||||||
154 | { |
||||||
155 | $configuration = new Configuration('TheCodingMachine\\TDBM\\Test\\Dao\\Bean', 'TheCodingMachine\\TDBM\\Test\\Dao', self::getConnection(), null, self::getCache(), null, null, []); |
||||||
156 | $configuration->setPathFinder(new PathFinder(null, dirname(__DIR__, 5))); |
||||||
157 | return $configuration; |
||||||
158 | } |
||||||
159 | |||||||
160 | /** |
||||||
161 | * @var ConfigurationInterface |
||||||
162 | */ |
||||||
163 | private $configuration; |
||||||
164 | |||||||
165 | protected function getConfiguration(): ConfigurationInterface |
||||||
166 | { |
||||||
167 | if ($this->configuration === null) { |
||||||
168 | return self::createConfiguration(); |
||||||
169 | } |
||||||
170 | return $this->configuration; |
||||||
171 | } |
||||||
172 | |||||||
173 | /** |
||||||
174 | * @Iterations(10) |
||||||
175 | */ |
||||||
176 | public function benchManyToOne(): void |
||||||
177 | { |
||||||
178 | $tdbmService = $this->getTdbmService(); |
||||||
179 | $userDao = new UserDao($tdbmService); |
||||||
180 | foreach ($userDao->findAll() as $user) { |
||||||
181 | $label = $user->getCountry()->getLabel(); |
||||||
0 ignored issues
–
show
|
|||||||
182 | } |
||||||
183 | } |
||||||
184 | } |
||||||
185 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths