Skip to content

Commit 937871c

Browse files
committed
starting adding types to codebase
1 parent a1eed00 commit 937871c

27 files changed

+134
-134
lines changed

src/Phinx/Config/Config.php

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Config implements ConfigInterface, NamespaceAwareInterface
4949
* @param array $configArray Config array
5050
* @param string|null $configFilePath Config file path
5151
*/
52-
public function __construct(array $configArray, $configFilePath = null)
52+
public function __construct(array $configArray, ?string $configFilePath = null)
5353
{
5454
$this->configFilePath = $configFilePath;
5555
$this->values = $this->replaceTokens($configArray);
@@ -62,7 +62,7 @@ public function __construct(array $configArray, $configFilePath = null)
6262
* @throws \RuntimeException
6363
* @return \Phinx\Config\Config
6464
*/
65-
public static function fromYaml($configFilePath)
65+
public static function fromYaml(string $configFilePath): Config
6666
{
6767
if (!class_exists('Symfony\\Component\\Yaml\\Yaml', true)) {
6868
// @codeCoverageIgnoreStart
@@ -90,7 +90,7 @@ public static function fromYaml($configFilePath)
9090
* @throws \RuntimeException
9191
* @return \Phinx\Config\Config
9292
*/
93-
public static function fromJson($configFilePath)
93+
public static function fromJson(string $configFilePath): Config
9494
{
9595
if (!function_exists('json_decode')) {
9696
// @codeCoverageIgnoreStart
@@ -116,7 +116,7 @@ public static function fromJson($configFilePath)
116116
* @throws \RuntimeException
117117
* @return \Phinx\Config\Config
118118
*/
119-
public static function fromPhp($configFilePath)
119+
public static function fromPhp(string $configFilePath): Config
120120
{
121121
ob_start();
122122
/** @noinspection PhpIncludeInspection */
@@ -138,7 +138,7 @@ public static function fromPhp($configFilePath)
138138
/**
139139
* @inheritDoc
140140
*/
141-
public function getEnvironments()
141+
public function getEnvironments(): ?array
142142
{
143143
if (isset($this->values) && isset($this->values['environments'])) {
144144
$environments = [];
@@ -157,7 +157,7 @@ public function getEnvironments()
157157
/**
158158
* @inheritDoc
159159
*/
160-
public function getEnvironment($name)
160+
public function getEnvironment(string $name): ?array
161161
{
162162
$environments = $this->getEnvironments();
163163

@@ -187,15 +187,15 @@ public function getEnvironment($name)
187187
/**
188188
* @inheritDoc
189189
*/
190-
public function hasEnvironment($name)
190+
public function hasEnvironment(string $name): bool
191191
{
192192
return $this->getEnvironment($name) !== null;
193193
}
194194

195195
/**
196196
* @inheritDoc
197197
*/
198-
public function getDefaultEnvironment()
198+
public function getDefaultEnvironment(): string
199199
{
200200
// The $PHINX_ENVIRONMENT variable overrides all other default settings
201201
$env = getenv('PHINX_ENVIRONMENT');
@@ -242,23 +242,23 @@ public function getDefaultEnvironment()
242242
/**
243243
* @inheritDoc
244244
*/
245-
public function getAlias($alias)
245+
public function getAlias($alias): ?string
246246
{
247247
return !empty($this->values['aliases'][$alias]) ? $this->values['aliases'][$alias] : null;
248248
}
249249

250250
/**
251251
* @inheritDoc
252252
*/
253-
public function getAliases()
253+
public function getAliases(): array
254254
{
255255
return !empty($this->values['aliases']) ? $this->values['aliases'] : [];
256256
}
257257

258258
/**
259259
* @inheritDoc
260260
*/
261-
public function getConfigFilePath()
261+
public function getConfigFilePath(): string
262262
{
263263
return $this->configFilePath;
264264
}
@@ -267,7 +267,7 @@ public function getConfigFilePath()
267267
* @inheritDoc
268268
* @throws \UnexpectedValueException
269269
*/
270-
public function getMigrationPaths()
270+
public function getMigrationPaths(): array
271271
{
272272
if (!isset($this->values['paths']['migrations'])) {
273273
throw new UnexpectedValueException('Migrations path missing from config file');
@@ -280,24 +280,11 @@ public function getMigrationPaths()
280280
return $this->values['paths']['migrations'];
281281
}
282282

283-
/**
284-
* Gets the base class name for migrations.
285-
*
286-
* @param bool $dropNamespace Return the base migration class name without the namespace.
287-
* @return string
288-
*/
289-
public function getMigrationBaseClassName($dropNamespace = true)
290-
{
291-
$className = !isset($this->values['migration_base_class']) ? 'Phinx\Migration\AbstractMigration' : $this->values['migration_base_class'];
292-
293-
return $dropNamespace ? (substr(strrchr($className, '\\'), 1) ?: $className) : $className;
294-
}
295-
296283
/**
297284
* @inheritDoc
298285
* @throws \UnexpectedValueException
299286
*/
300-
public function getSeedPaths()
287+
public function getSeedPaths(): array
301288
{
302289
if (!isset($this->values['paths']['seeds'])) {
303290
throw new UnexpectedValueException('Seeds path missing from config file');
@@ -310,13 +297,26 @@ public function getSeedPaths()
310297
return $this->values['paths']['seeds'];
311298
}
312299

300+
/**
301+
* Gets the base class name for migrations.
302+
*
303+
* @param bool $dropNamespace Return the base migration class name without the namespace.
304+
* @return string
305+
*/
306+
public function getMigrationBaseClassName(bool $dropNamespace = true): string
307+
{
308+
$className = !isset($this->values['migration_base_class']) ? 'Phinx\Migration\AbstractMigration' : $this->values['migration_base_class'];
309+
310+
return $dropNamespace ? (substr(strrchr($className, '\\'), 1) ?: $className) : $className;
311+
}
312+
313313
/**
314314
* Gets the base class name for seeders.
315315
*
316316
* @param bool $dropNamespace Return the base seeder class name without the namespace.
317317
* @return string
318318
*/
319-
public function getSeedBaseClassName($dropNamespace = true)
319+
public function getSeedBaseClassName(bool $dropNamespace = true): string
320320
{
321321
$className = !isset($this->values['seed_base_class']) ? 'Phinx\Seed\AbstractSeed' : $this->values['seed_base_class'];
322322

@@ -354,7 +354,7 @@ public function getTemplateClass()
354354
/**
355355
* {@inheritdoc}
356356
*/
357-
public function getDataDomain()
357+
public function getDataDomain(): array
358358
{
359359
if (!isset($this->values['data_domain'])) {
360360
return [];
@@ -366,7 +366,7 @@ public function getDataDomain()
366366
/**
367367
* @inheritDoc
368368
*/
369-
public function getContainer()
369+
public function getContainer(): ?\Psr\Container\ContainerInterface
370370
{
371371
if (!isset($this->values['container'])) {
372372
return null;
@@ -380,7 +380,7 @@ public function getContainer()
380380
*
381381
* @return string
382382
*/
383-
public function getVersionOrder()
383+
public function getVersionOrder(): string
384384
{
385385
if (!isset($this->values['version_order'])) {
386386
return self::VERSION_ORDER_CREATION_TIME;
@@ -394,7 +394,7 @@ public function getVersionOrder()
394394
*
395395
* @return bool
396396
*/
397-
public function isVersionOrderCreationTime()
397+
public function isVersionOrderCreationTime(): bool
398398
{
399399
$versionOrder = $this->getVersionOrder();
400400

@@ -421,7 +421,7 @@ public function getBootstrapFile()
421421
* @param array $arr Array to replace
422422
* @return array
423423
*/
424-
protected function replaceTokens(array $arr)
424+
protected function replaceTokens(array $arr): array
425425
{
426426
// Get environment variables
427427
// Depending on configuration of server / OS and variables_order directive,
@@ -449,7 +449,7 @@ protected function replaceTokens(array $arr)
449449
* @param string[] $tokens Array of tokens to search for
450450
* @return array
451451
*/
452-
protected function recurseArrayForTokens($arr, $tokens)
452+
protected function recurseArrayForTokens(array $arr, array $tokens): array
453453
{
454454
$out = [];
455455
foreach ($arr as $name => $value) {
@@ -476,7 +476,7 @@ protected function recurseArrayForTokens($arr, $tokens)
476476
* @param array $options Options
477477
* @return array
478478
*/
479-
protected function parseAgnosticDsn(array $options)
479+
protected function parseAgnosticDsn(array $options): array
480480
{
481481
$parsed = Util::parseDsn($options['dsn'] ?? '');
482482
if ($parsed) {
@@ -495,7 +495,7 @@ protected function parseAgnosticDsn(array $options)
495495
* @param mixed $value Value
496496
* @return void
497497
*/
498-
public function offsetSet($id, $value)
498+
public function offsetSet($id, $value): void
499499
{
500500
$this->values[$id] = $value;
501501
}
@@ -522,7 +522,7 @@ public function offsetGet($id)
522522
* @param mixed $id ID
523523
* @return bool
524524
*/
525-
public function offsetExists($id)
525+
public function offsetExists($id): bool
526526
{
527527
return isset($this->values[$id]);
528528
}
@@ -533,7 +533,7 @@ public function offsetExists($id)
533533
* @param mixed $id ID
534534
* @return void
535535
*/
536-
public function offsetUnset($id)
536+
public function offsetUnset($id): void
537537
{
538538
unset($this->values[$id]);
539539
}

src/Phinx/Config/ConfigInterface.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ interface ConfigInterface extends ArrayAccess
2424
*
2525
* @return array|null
2626
*/
27-
public function getEnvironments();
27+
public function getEnvironments(): ?array;
2828

2929
/**
3030
* Returns the configuration for a given environment.
@@ -35,59 +35,59 @@ public function getEnvironments();
3535
* @param string $name Environment Name
3636
* @return array|null
3737
*/
38-
public function getEnvironment($name);
38+
public function getEnvironment(string $name): ?array;
3939

4040
/**
4141
* Does the specified environment exist in the configuration file?
4242
*
4343
* @param string $name Environment Name
4444
* @return bool
4545
*/
46-
public function hasEnvironment($name);
46+
public function hasEnvironment(string $name): bool;
4747

4848
/**
4949
* Gets the default environment name.
5050
*
5151
* @throws \RuntimeException
5252
* @return string
5353
*/
54-
public function getDefaultEnvironment();
54+
public function getDefaultEnvironment(): string;
5555

5656
/**
5757
* Get the aliased value from a supplied alias.
5858
*
5959
* @param string $alias Alias
6060
* @return string|null
6161
*/
62-
public function getAlias($alias);
62+
public function getAlias(string $alias): ?string;
6363

6464
/**
6565
* Get all the aliased values.
6666
*
6767
* @return string[]
6868
*/
69-
public function getAliases();
69+
public function getAliases(): array;
7070

7171
/**
7272
* Gets the config file path.
7373
*
7474
* @return string
7575
*/
76-
public function getConfigFilePath();
76+
public function getConfigFilePath(): string;
7777

7878
/**
7979
* Gets the paths to search for migration files.
8080
*
8181
* @return string[]
8282
*/
83-
public function getMigrationPaths();
83+
public function getMigrationPaths(): array;
8484

8585
/**
8686
* Gets the paths to search for seed files.
8787
*
8888
* @return string[]
8989
*/
90-
public function getSeedPaths();
90+
public function getSeedPaths(): array;
9191

9292
/**
9393
* Get the template file name.
@@ -108,28 +108,28 @@ public function getTemplateClass();
108108
*
109109
* @return \Psr\Container\ContainerInterface|null
110110
*/
111-
public function getContainer();
111+
public function getContainer(): ?\Psr\Container\ContainerInterface;
112112

113113
/**
114114
* Get the data domain array.
115115
*
116116
* @return array
117117
*/
118-
public function getDataDomain();
118+
public function getDataDomain(): array;
119119

120120
/**
121121
* Get the version order.
122122
*
123123
* @return string
124124
*/
125-
public function getVersionOrder();
125+
public function getVersionOrder(): string;
126126

127127
/**
128128
* Is version order creation time?
129129
*
130130
* @return bool
131131
*/
132-
public function isVersionOrderCreationTime();
132+
public function isVersionOrderCreationTime(): bool;
133133

134134
/**
135135
* Get the bootstrap file path
@@ -144,13 +144,13 @@ public function getBootstrapFile();
144144
* @param bool $dropNamespace Return the base migration class name without the namespace.
145145
* @return string
146146
*/
147-
public function getMigrationBaseClassName($dropNamespace = true);
147+
public function getMigrationBaseClassName(bool $dropNamespace = true): string;
148148

149149
/**
150150
* Gets the base class name for seeders.
151151
*
152152
* @param bool $dropNamespace Return the base seeder class name without the namespace.
153153
* @return string
154154
*/
155-
public function getSeedBaseClassName($dropNamespace = true);
155+
public function getSeedBaseClassName(bool $dropNamespace = true): string;
156156
}

src/Phinx/Config/NamespaceAwareInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ interface NamespaceAwareInterface
2121
* @param string $path Path
2222
* @return string|null
2323
*/
24-
public function getMigrationNamespaceByPath($path);
24+
public function getMigrationNamespaceByPath(string $path): ?string;
2525

2626
/**
2727
* Get Seed Namespace associated with path.
2828
*
2929
* @param string $path Path
3030
* @return string|null
3131
*/
32-
public function getSeedNamespaceByPath($path);
32+
public function getSeedNamespaceByPath(string $path): ?string;
3333
}

0 commit comments

Comments
 (0)