diff --git a/packages/admin/src/Charcoal/Admin/Config.php b/packages/admin/src/Charcoal/Admin/Config.php index 0f750216a..5fd4c9949 100644 --- a/packages/admin/src/Charcoal/Admin/Config.php +++ b/packages/admin/src/Charcoal/Admin/Config.php @@ -50,7 +50,7 @@ class Config extends AbstractConfig * * @return array */ - public function defaults() + public function defaults(): array { $baseDir = rtrim(realpath(__DIR__ . '/../../../'), '/'); $confDir = $baseDir . '/config'; diff --git a/packages/admin/src/Charcoal/Admin/User/AuthTokenMetadata.php b/packages/admin/src/Charcoal/Admin/User/AuthTokenMetadata.php index 9874dfae5..36161df0c 100644 --- a/packages/admin/src/Charcoal/Admin/User/AuthTokenMetadata.php +++ b/packages/admin/src/Charcoal/Admin/User/AuthTokenMetadata.php @@ -13,7 +13,7 @@ class AuthTokenMetadata extends BaseAuthTokenMetadata /** * @return array */ - public function defaults() + public function defaults(): array { $parentDefaults = parent::defaults(); diff --git a/packages/app/src/Charcoal/App/AppConfig.php b/packages/app/src/Charcoal/App/AppConfig.php index 8c7b8a809..0853462af 100644 --- a/packages/app/src/Charcoal/App/AppConfig.php +++ b/packages/app/src/Charcoal/App/AppConfig.php @@ -19,68 +19,51 @@ class AppConfig extends AbstractConfig { /** * The application's timezone. - * - * @var string|null */ - private $timezone; + private ?string $timezone; /** * The application's name. * * For internal usage. - * - * @var string|null */ - private $projectName; + private ?string $projectName; /** * The base URL (public) for the Charcoal installation. - * - * @var UriInterface|null */ - private $baseUrl; + private ?UriInterface $baseUrl = null; /** * The base path for the Charcoal installation. - * - * @var string|null */ - private $basePath; + private ?string $basePath = null; /** * The path to the public / web directory. * - * @var string|null */ - private $publicPath; + private ?string $publicPath = null; /** * The path to the cache directory. - * - * @var string|null */ - private $cachePath; + private ?string $cachePath = null; /** * The path to the logs directory. - * - * @var string|null */ - private $logsPath; + private ?string $logsPath = null; /** * Whether the debug mode is enabled (TRUE) or not (FALSE). - * - * @var boolean */ - private $devMode = false; + private bool $devMode = false; /** * The application's routes. - * - * @var array */ - private $routes = []; + private array $routes = []; /** * The application's dynamic routes. @@ -91,84 +74,63 @@ class AppConfig extends AbstractConfig /** * The application's HTTP middleware. - * - * @var array */ - private $middlewares = []; + private array $middlewares = []; /** * The application's handlers. - * - * @var array */ - private $handlers = []; + private array $handlers = []; /** * The application's modules. - * - * @var array */ - private $modules = []; + private array $modules = []; /** * The application's API credentials and service configsets. - * - * @var array */ - private $apis = []; + private array $apis = []; /** * The application's caching configset. - * - * @var array */ - private $cache; + private array $cache = []; /** * The application's logging configset. * * @var array */ - private $logger; + private array $logger = []; /** * The application's view/rendering configset. - * - * @var array */ - protected $view; + protected array $view = []; /** * The application's database configsets. - * - * @var array */ - private $databases = []; + private array $databases = []; /** * The application's default database configset. - * - * @var string */ - private $defaultDatabase; + private ?string $defaultDatabase; /** * The application's filesystem configset. - * - * @var array */ - private $filesystem; + private array $filesystem = []; /** * Default app-config values. * * @return array */ - public function defaults() + public function defaults(): array { - /** @var string $baseDir Presume that Charcoal App _is_ the application */ - $baseDir = rtrim(realpath(__DIR__ . '/../../../'), '/') . '/'; - return [ 'project_name' => '', 'timezone' => 'UTC', @@ -182,7 +144,7 @@ public function defaults() 'view' => [], 'databases' => [], 'default_database' => 'default', - 'dev_mode' => false + 'dev_mode' => false, ]; } @@ -209,7 +171,7 @@ public function resolveValue($value) 'app.public_path' => $this->publicPath(), 'app.cache_path' => $this->cachePath(), 'app.logs_path' => $this->logsPath(), - 'packages.path' => ($_ENV['PACKAGES_PATH'] ?? 'vendor/charcoal') + 'packages.path' => ($_ENV['PACKAGES_PATH'] ?? 'vendor/charcoal'), ]; if (is_string($value)) { @@ -251,7 +213,7 @@ public function resolveValue($value) * @param string $path The file to load and add. * @return self */ - public function addFile($path) + public function addFile(string $path): self { $path = $this->resolveValue($path); @@ -263,11 +225,11 @@ public function addFile($path) * * Resolves symlinks with realpath() and ensure trailing slash. * - * @param string $path The absolute path to the application's root directory. + * @param string|null $path The absolute path to the application's root directory. * @throws InvalidArgumentException If the argument is not a string. * @return self */ - public function setBasePath($path) + public function setBasePath(?string $path): self { if ($path === null) { throw new InvalidArgumentException( @@ -290,7 +252,7 @@ public function setBasePath($path) * * @return string|null The absolute path to the application's root directory. */ - public function basePath() + public function basePath(): ?string { return $this->basePath; } @@ -298,11 +260,11 @@ public function basePath() /** * Set the application's absolute path to the public web directory. * - * @param string $path The path to the application's public directory. + * @param string|null $path The path to the application's public directory. * @throws InvalidArgumentException If the argument is not a string. * @return self */ - public function setPublicPath($path) + public function setPublicPath(?string $path): self { if ($path === null) { $this->publicPath = null; @@ -324,7 +286,7 @@ public function setPublicPath($path) * * @return string The absolute path to the application's public directory. */ - public function publicPath() + public function publicPath(): string { if ($this->publicPath === null) { $this->publicPath = $this->basePath() . DIRECTORY_SEPARATOR . 'www'; @@ -336,11 +298,11 @@ public function publicPath() /** * Set the application's absolute path to the cache directory. * - * @param string $path The path to the application's cache directory. + * @param string|null $path The path to the application's cache directory. * @throws InvalidArgumentException If the argument is not a string. * @return self */ - public function setCachePath($path) + public function setCachePath(?string $path): self { if ($path === null) { $this->cachePath = null; @@ -362,7 +324,7 @@ public function setCachePath($path) * * @return string The absolute path to the application's cache directory. */ - public function cachePath() + public function cachePath(): string { if ($this->cachePath === null) { $this->cachePath = $this->basePath() . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'cache'; @@ -374,11 +336,11 @@ public function cachePath() /** * Set the application's absolute path to the logs directory. * - * @param string $path The path to the application's logs directory. + * @param string|null $path The path to the application's logs directory. * @throws InvalidArgumentException If the argument is not a string. * @return self */ - public function setLogsPath($path) + public function setLogsPath(?string $path): self { if ($path === null) { $this->logsPath = null; @@ -400,7 +362,7 @@ public function setLogsPath($path) * * @return string The absolute path to the application's logs directory. */ - public function logsPath() + public function logsPath(): string { if ($this->logsPath === null) { $this->logsPath = $this->basePath() . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'logs'; @@ -415,7 +377,7 @@ public function logsPath() * @param UriInterface|string $uri The base URI to the application's web directory. * @return self */ - public function setBaseUrl($uri) + public function setBaseUrl($uri): self { if (is_string($uri)) { $this->baseUrl = Uri::createFromString($uri); @@ -430,7 +392,7 @@ public function setBaseUrl($uri) * * @return UriInterface|null The base URI to the application's web directory. */ - public function baseUrl() + public function baseUrl(): ?UriInterface { return $this->baseUrl; } @@ -442,14 +404,8 @@ public function baseUrl() * @throws InvalidArgumentException If the argument is not a string. * @return self */ - public function setTimezone($timezone) + public function setTimezone(string $timezone): self { - if (!is_string($timezone)) { - throw new InvalidArgumentException( - 'Timezone must be a string.' - ); - } - $this->timezone = $timezone; return $this; } @@ -461,13 +417,9 @@ public function setTimezone($timezone) * * @return string */ - public function timezone() + public function timezone(): string { - if (isset($this->timezone)) { - return $this->timezone; - } else { - return 'UTC'; - } + return ($this->timezone ?? 'UTC'); } /** @@ -477,7 +429,7 @@ public function timezone() * @throws InvalidArgumentException If the project argument is not a string (or null). * @return self */ - public function setProjectName($projectName) + public function setProjectName(?string $projectName): self { if ($projectName === null) { $this->projectName = null; @@ -496,7 +448,7 @@ public function setProjectName($projectName) /** * @return string|null */ - public function projectName() + public function projectName(): ?string { if ($this->projectName === null) { $baseUrl = $this->baseUrl(); @@ -512,7 +464,7 @@ public function projectName() * @param boolean $devMode The "dev mode" flag. * @return self */ - public function setDevMode($devMode) + public function setDevMode(bool $devMode): self { $this->devMode = !!$devMode; return $this; @@ -521,7 +473,7 @@ public function setDevMode($devMode) /** * @return boolean */ - public function devMode() + public function devMode(): bool { return !!$this->devMode; } @@ -533,7 +485,7 @@ public function devMode() * @throws InvalidArgumentException If the argument is not a configset. * @return self */ - public function setView(array $view) + public function setView(array $view): self { $this->view = $view; return $this; @@ -544,7 +496,7 @@ public function setView(array $view) * * @return array */ - public function view() + public function view(): array { return $this->view; } @@ -555,7 +507,7 @@ public function view() * @param array $apis The API configuration structure to set. * @return self */ - public function setApis(array $apis) + public function setApis(array $apis): self { $this->apis = $apis; return $this; @@ -564,7 +516,7 @@ public function setApis(array $apis) /** * @return array */ - public function apis() + public function apis(): array { return $this->apis; } @@ -576,7 +528,7 @@ public function apis() * @param array $routes The route configuration structure to set. * @return self */ - public function setRoutes(array $routes) + public function setRoutes(array $routes): self { $this->routes = $routes; return $this; @@ -585,7 +537,7 @@ public function setRoutes(array $routes) /** * @return array */ - public function routes() + public function routes(): array { return $this->routes; } @@ -594,7 +546,7 @@ public function routes() * @param array|boolean $routables The routable configuration structure to set or FALSE to disable dynamic routing. * @return self */ - public function setRoutables($routables) + public function setRoutables($routables): self { if ($routables !== false) { if (!is_array($routables) || empty($routables)) { @@ -620,7 +572,7 @@ public function routables() * @param array $middlewares The middleware configuration structure to set. * @return self */ - public function setMiddlewares(array $middlewares) + public function setMiddlewares(array $middlewares): self { $this->middlewares = $middlewares; return $this; @@ -629,7 +581,7 @@ public function setMiddlewares(array $middlewares) /** * @return array */ - public function middlewares() + public function middlewares(): array { return $this->middlewares; } @@ -647,7 +599,7 @@ public function middlewares() * @param array $handlers The handlers configuration structure to set. * @return self */ - public function setHandlers(array $handlers) + public function setHandlers(array $handlers): self { $this->handlers = $handlers; return $this; @@ -656,7 +608,7 @@ public function setHandlers(array $handlers) /** * @return array */ - public function handlers() + public function handlers(): array { return $this->handlers; } @@ -667,7 +619,7 @@ public function handlers() * @param array $modules The module configuration structure to set. * @return self */ - public function setModules(array $modules) + public function setModules(array $modules): self { $this->modules = $modules; return $this; @@ -676,7 +628,7 @@ public function setModules(array $modules) /** * @return array */ - public function modules() + public function modules(): array { return $this->modules; } @@ -688,7 +640,7 @@ public function modules() * @throws InvalidArgumentException If the argument is not a configset. * @return self */ - public function setCache(array $cache) + public function setCache(array $cache): self { $this->cache = $cache; return $this; @@ -699,7 +651,7 @@ public function setCache(array $cache) * * @return array */ - public function cache() + public function cache(): array { return $this->cache; } @@ -711,7 +663,7 @@ public function cache() * @throws InvalidArgumentException If the argument is not a configset. * @return self */ - public function setLogger(array $logger) + public function setLogger(array $logger): self { $this->logger = $logger; return $this; @@ -722,16 +674,16 @@ public function setLogger(array $logger) * * @return array */ - public function logger() + public function logger(): array { return $this->logger; } /** - * @param array $databases The avaiable databases config. + * @param array $databases The available databases config. * @return self */ - public function setDatabases(array $databases) + public function setDatabases(array $databases): self { $this->databases = $databases; return $this; @@ -741,7 +693,7 @@ public function setDatabases(array $databases) * @throws Exception If trying to access this method and no databases were set. * @return array */ - public function databases() + public function databases(): array { if ($this->databases === null) { throw new Exception( @@ -757,13 +709,8 @@ public function databases() * @throws Exception If trying to access an invalid database. * @return array */ - public function databaseConfig($ident) + public function databaseConfig(string $ident): array { - if (!is_string($ident)) { - throw new InvalidArgumentException( - 'Invalid app config: default database must be a string.' - ); - } $databases = $this->databases(); if (!isset($databases[$ident])) { throw new Exception( @@ -778,13 +725,8 @@ public function databaseConfig($ident) * @throws InvalidArgumentException If the argument is not a string. * @return self */ - public function setDefaultDatabase($defaultDatabase) + public function setDefaultDatabase(string $defaultDatabase): self { - if (!is_string($defaultDatabase)) { - throw new InvalidArgumentException( - 'Invalid app config: Default database must be a string.' - ); - } $this->defaultDatabase = $defaultDatabase; return $this; } @@ -795,14 +737,8 @@ public function setDefaultDatabase($defaultDatabase) * @throws InvalidArgumentException If the arguments are invalid. * @return self */ - public function addDatabase($ident, array $config) + public function addDatabase(string $ident, array $config): self { - if (!is_string($ident)) { - throw new InvalidArgumentException( - 'Invalid app config: database ident must be a string.' - ); - } - if ($this->databases === null) { $this->databases = []; } @@ -812,9 +748,9 @@ public function addDatabase($ident, array $config) /** * @throws Exception If trying to access this method before a setter. - * @return mixed + * @return string */ - public function defaultDatabase() + public function defaultDatabase(): string { if ($this->defaultDatabase === null) { throw new Exception( @@ -831,7 +767,7 @@ public function defaultDatabase() * @throws InvalidArgumentException If the argument is not a configset. * @return self */ - public function setFilesystem(array $filesystem) + public function setFilesystem(array $filesystem): self { $this->filesystem = $filesystem; return $this; @@ -842,7 +778,7 @@ public function setFilesystem(array $filesystem) * * @return array */ - public function filesystem() + public function filesystem(): array { return $this->filesystem; } diff --git a/packages/app/src/Charcoal/App/Config/DatabaseConfig.php b/packages/app/src/Charcoal/App/Config/DatabaseConfig.php index c5533aa49..a76296eb3 100644 --- a/packages/app/src/Charcoal/App/Config/DatabaseConfig.php +++ b/packages/app/src/Charcoal/App/Config/DatabaseConfig.php @@ -44,7 +44,7 @@ class DatabaseConfig extends AbstractConfig /** * @return array */ - public function defaults() + public function defaults(): array { return [ 'type' => 'mysql', diff --git a/packages/app/src/Charcoal/App/Config/LoggerConfig.php b/packages/app/src/Charcoal/App/Config/LoggerConfig.php index 800314189..214056ff1 100644 --- a/packages/app/src/Charcoal/App/Config/LoggerConfig.php +++ b/packages/app/src/Charcoal/App/Config/LoggerConfig.php @@ -50,7 +50,7 @@ class LoggerConfig extends AbstractConfig * * @return array */ - public function defaults() + public function defaults(): array { return [ 'active' => true, diff --git a/packages/cache/src/Charcoal/Cache/CacheConfig.php b/packages/cache/src/Charcoal/Cache/CacheConfig.php index 041df2bc9..ad8724fb6 100644 --- a/packages/cache/src/Charcoal/Cache/CacheConfig.php +++ b/packages/cache/src/Charcoal/Cache/CacheConfig.php @@ -66,7 +66,7 @@ class CacheConfig extends AbstractConfig * * @return array */ - public function defaults() + public function defaults(): array { return [ 'active' => true, diff --git a/packages/cache/src/Charcoal/Cache/Middleware/CacheMiddleware.php b/packages/cache/src/Charcoal/Cache/Middleware/CacheMiddleware.php index 1c94a670c..f71037999 100644 --- a/packages/cache/src/Charcoal/Cache/Middleware/CacheMiddleware.php +++ b/packages/cache/src/Charcoal/Cache/Middleware/CacheMiddleware.php @@ -145,7 +145,7 @@ public function __construct(array $data) * * @return array */ - public function defaults() + public function defaults(): array { return [ 'ttl' => CacheConfig::DAY_IN_SECONDS, diff --git a/packages/config/src/Charcoal/Config/AbstractConfig.php b/packages/config/src/Charcoal/Config/AbstractConfig.php index d9a33d9e8..5a06b0f8b 100644 --- a/packages/config/src/Charcoal/Config/AbstractConfig.php +++ b/packages/config/src/Charcoal/Config/AbstractConfig.php @@ -82,7 +82,7 @@ final public function __construct($data = null, array $delegates = null) * * @return array Key-value array of data */ - public function defaults() + public function defaults(): array { return []; } @@ -96,7 +96,7 @@ public function defaults() * (such as {@see ConfigInterface}). * @return self */ - public function merge($data) + public function merge($data): self { foreach ($data as $key => $value) { $this->offsetReplace($key, $value); @@ -334,7 +334,7 @@ public function offsetReplace($key, $value) * @param string $path The file to load and add. * @return self */ - public function addFile($path) + public function addFile(string $path): self { $config = $this->loadFile($path); if (is_array($config)) { diff --git a/packages/config/src/Charcoal/Config/ConfigInterface.php b/packages/config/src/Charcoal/Config/ConfigInterface.php index 780dcd384..83ed59e94 100644 --- a/packages/config/src/Charcoal/Config/ConfigInterface.php +++ b/packages/config/src/Charcoal/Config/ConfigInterface.php @@ -18,7 +18,7 @@ interface ConfigInterface extends * * @return array Key-value array of data */ - public function defaults(); + public function defaults(): array; /** * Adds new data, replacing / merging existing data with the same key. @@ -26,7 +26,7 @@ public function defaults(); * @param array|\Traversable $data Key-value array of data to merge. * @return ConfigInterface Chainable */ - public function merge($data); + public function merge(array $data): ConfigInterface; /** * Add a configuration file to the configset. @@ -34,5 +34,5 @@ public function merge($data); * @param string $path The file to load and add. * @return ConfigInterface Chainable */ - public function addFile($path); + public function addFile(string $path): ConfigInterface; } diff --git a/packages/config/tests/Charcoal/Config/Mock/MacroConfig.php b/packages/config/tests/Charcoal/Config/Mock/MacroConfig.php index 9a4dd4933..128abc9a3 100644 --- a/packages/config/tests/Charcoal/Config/Mock/MacroConfig.php +++ b/packages/config/tests/Charcoal/Config/Mock/MacroConfig.php @@ -16,7 +16,7 @@ class MacroConfig extends AbstractConfig /** * @return array */ - public function defaults() + public function defaults(): array { return [ 'foo' => -3, diff --git a/packages/core/src/Charcoal/Model/Service/MetadataConfig.php b/packages/core/src/Charcoal/Model/Service/MetadataConfig.php index 446dc61bf..442f59c20 100644 --- a/packages/core/src/Charcoal/Model/Service/MetadataConfig.php +++ b/packages/core/src/Charcoal/Model/Service/MetadataConfig.php @@ -34,7 +34,7 @@ class MetadataConfig extends AbstractConfig * @return mixed An associative array if $key is NULL. * If $key is specified, the value of that data key if it exists, NULL on failure. */ - public function defaults($key = null) + public function defaults($key = null): array { $data = [ 'paths' => [], @@ -55,7 +55,7 @@ public function defaults($key = null) * @param array|Traversable $data The data to merge. * @return self */ - public function merge($data) + public function merge($data): self { foreach ($data as $key => $val) { if ($key === 'paths') { diff --git a/packages/core/src/Charcoal/Source/DatabaseSourceConfig.php b/packages/core/src/Charcoal/Source/DatabaseSourceConfig.php index 6cfe1042c..1cfbfee80 100644 --- a/packages/core/src/Charcoal/Source/DatabaseSourceConfig.php +++ b/packages/core/src/Charcoal/Source/DatabaseSourceConfig.php @@ -44,7 +44,7 @@ class DatabaseSourceConfig extends SourceConfig /** * @return array */ - public function defaults() + public function defaults(): array { return [ 'type' => 'mysql', diff --git a/packages/core/src/Charcoal/Source/SourceConfig.php b/packages/core/src/Charcoal/Source/SourceConfig.php index 5f4081606..09b9b756a 100644 --- a/packages/core/src/Charcoal/Source/SourceConfig.php +++ b/packages/core/src/Charcoal/Source/SourceConfig.php @@ -19,7 +19,7 @@ class SourceConfig extends AbstractConfig /** * @return array */ - public function defaults() + public function defaults(): array { return [ 'type' => '' diff --git a/packages/translator/src/Charcoal/Translator/LocalesConfig.php b/packages/translator/src/Charcoal/Translator/LocalesConfig.php index 7640c6111..f042e59d4 100644 --- a/packages/translator/src/Charcoal/Translator/LocalesConfig.php +++ b/packages/translator/src/Charcoal/Translator/LocalesConfig.php @@ -37,7 +37,7 @@ class LocalesConfig extends AbstractConfig /** * @return array */ - public function defaults() + public function defaults(): array { return [ 'languages' => [ diff --git a/packages/translator/src/Charcoal/Translator/Middleware/LanguageMiddleware.php b/packages/translator/src/Charcoal/Translator/Middleware/LanguageMiddleware.php index 388157429..4ebaec46b 100644 --- a/packages/translator/src/Charcoal/Translator/Middleware/LanguageMiddleware.php +++ b/packages/translator/src/Charcoal/Translator/Middleware/LanguageMiddleware.php @@ -119,7 +119,7 @@ public function __construct(array $data) * * @return array */ - public function defaults() + public function defaults(): array { return [ 'default_language' => null, diff --git a/packages/translator/src/Charcoal/Translator/TranslatorConfig.php b/packages/translator/src/Charcoal/Translator/TranslatorConfig.php index 9063debdb..29a2d1e77 100644 --- a/packages/translator/src/Charcoal/Translator/TranslatorConfig.php +++ b/packages/translator/src/Charcoal/Translator/TranslatorConfig.php @@ -52,7 +52,7 @@ class TranslatorConfig extends AbstractConfig /** * @return array */ - public function defaults() + public function defaults(): array { return [ 'loaders' => [ diff --git a/packages/user/src/Charcoal/User/AuthTokenMetadata.php b/packages/user/src/Charcoal/User/AuthTokenMetadata.php index 43c445d54..de39268a0 100644 --- a/packages/user/src/Charcoal/User/AuthTokenMetadata.php +++ b/packages/user/src/Charcoal/User/AuthTokenMetadata.php @@ -36,7 +36,7 @@ class AuthTokenMetadata extends ModelMetadata * * @return array */ - public function defaults() + public function defaults(): array { $parentDefaults = parent::defaults();