diff --git a/config/api/authentication.php b/config/api/authentication.php index a86602a23b..0cee131a5e 100644 --- a/config/api/authentication.php +++ b/config/api/authentication.php @@ -11,7 +11,7 @@ $auth->type($allowImpersonation) === 'session' && $auth->csrf() === false ) { - throw new AuthException('Unauthenticated'); + throw new AuthException(message: 'Unauthenticated'); } // get user from session or basic auth @@ -23,5 +23,5 @@ return $user; } - throw new AuthException('Unauthenticated'); + throw new AuthException(message: 'Unauthenticated'); }; diff --git a/config/areas/system/dialogs.php b/config/areas/system/dialogs.php index e8dd6946cd..db8b7a5560 100644 --- a/config/areas/system/dialogs.php +++ b/config/areas/system/dialogs.php @@ -53,7 +53,7 @@ ]; } - throw new LogicException('The upgrade failed'); + throw new LogicException(message: 'The upgrade failed'); // @codeCoverageIgnoreEnd } ], diff --git a/src/Api/Collection.php b/src/Api/Collection.php index af66235297..c9a9a16d16 100644 --- a/src/Api/Collection.php +++ b/src/Api/Collection.php @@ -40,7 +40,7 @@ public function __construct( if ($data === null) { if (($schema['default'] ?? null) instanceof Closure === false) { - throw new Exception('Missing collection data'); + throw new Exception(message: 'Missing collection data'); } $this->data = $schema['default']->call($this->api); @@ -50,7 +50,7 @@ public function __construct( isset($schema['type']) === true && $this->data instanceof $schema['type'] === false ) { - throw new Exception('Invalid collection type'); + throw new Exception(message: 'Invalid collection type'); } } @@ -69,7 +69,7 @@ public function select($keys = null): static } if ($keys !== null && is_array($keys) === false) { - throw new Exception('Invalid select keys'); + throw new Exception(message: 'Invalid select keys'); } $this->select = $keys; diff --git a/src/Api/Model.php b/src/Api/Model.php index 7e4071f287..fa3a000f2e 100644 --- a/src/Api/Model.php +++ b/src/Api/Model.php @@ -49,7 +49,7 @@ public function __construct( if ($data === null) { if (($schema['default'] ?? null) instanceof Closure === false) { - throw new Exception('Missing model data'); + throw new Exception(message: 'Missing model data'); } $this->data = $schema['default']->call($this->api); @@ -82,7 +82,7 @@ public function select($keys = null): static } if ($keys !== null && is_array($keys) === false) { - throw new Exception('Invalid select keys'); + throw new Exception(message: 'Invalid select keys'); } $this->select = $keys; @@ -109,7 +109,7 @@ public function selection(): array if (is_string($value) === true) { if ($value === 'any') { - throw new Exception('Invalid sub view: "any"'); + throw new Exception(message: 'Invalid sub view: "any"'); } $selection[$key] = [ diff --git a/src/Cms/Auth.php b/src/Cms/Auth.php index f53277762c..c75015b7ec 100644 --- a/src/Cms/Auth.php +++ b/src/Cms/Auth.php @@ -343,7 +343,7 @@ public function impersonate(string|null $who = null): User|null 'id' => 'nobody', 'role' => 'nobody', ]), - default => ($this->kirby->users()->find($who) ?? throw new NotFoundException('The user "' . $who . '" cannot be found')) + default => $this->kirby->users()->find($who) ?? throw new NotFoundException(message: 'The user "' . $who . '" cannot be found') }; } diff --git a/src/Cms/Blocks.php b/src/Cms/Blocks.php index 529bf2fabb..1c817b2c43 100644 --- a/src/Cms/Blocks.php +++ b/src/Cms/Blocks.php @@ -138,7 +138,7 @@ public static function parse(array|string|null $input): array isset($first['type']) === false ) ) { - throw new Exception('Invalid YAML'); + throw new Exception(message: 'Invalid YAML'); } $input = $yaml; diff --git a/src/Cms/Collections.php b/src/Cms/Collections.php index beafe8d781..7266ad9ff4 100644 --- a/src/Cms/Collections.php +++ b/src/Cms/Collections.php @@ -119,7 +119,12 @@ public function load(string $name): mixed // fallback to collections from plugins $collections = $kirby->extensions('collections'); - return $collections[$name] ?? - throw new NotFoundException('The collection cannot be found'); + if ($collection = $collections[$name] ?? null) { + return $collection; + } + + throw new NotFoundException( + message: 'The collection cannot be found' + ); } } diff --git a/src/Cms/Email.php b/src/Cms/Email.php index a2b97a271f..d096350a24 100644 --- a/src/Cms/Email.php +++ b/src/Cms/Email.php @@ -114,7 +114,9 @@ protected function template(): void } elseif ($text->exists() === true) { $this->props['body'] = $text->render($data); } else { - throw new NotFoundException('The email template "' . $this->props['template'] . '" cannot be found'); + throw new NotFoundException( + message: 'The email template "' . $this->props['template'] . '" cannot be found' + ); } } } @@ -187,7 +189,9 @@ protected function transformModel( } } else { // invalid input - throw new InvalidArgumentException('Invalid input for prop "' . $prop . '", expected string or "' . $class . '" object or collection'); + throw new InvalidArgumentException( + message: 'Invalid input for prop "' . $prop . '", expected string or "' . $class . '" object or collection' + ); } } diff --git a/src/Cms/Event.php b/src/Cms/Event.php index 333aeffbc4..6c23e3321d 100644 --- a/src/Cms/Event.php +++ b/src/Cms/Event.php @@ -246,7 +246,9 @@ public function type(): string public function updateArgument(string $name, $value): void { if (array_key_exists($name, $this->arguments) !== true) { - throw new InvalidArgumentException('The argument ' . $name . ' does not exist'); + throw new InvalidArgumentException( + message: 'The argument ' . $name . ' does not exist' + ); } $this->arguments[$name] = $value; diff --git a/src/Cms/Fieldset.php b/src/Cms/Fieldset.php index 04d6ff19b8..a5dc9105bb 100644 --- a/src/Cms/Fieldset.php +++ b/src/Cms/Fieldset.php @@ -42,7 +42,9 @@ class Fieldset extends Item public function __construct(array $params = []) { if (empty($params['type']) === true) { - throw new InvalidArgumentException('The fieldset type is missing'); + throw new InvalidArgumentException( + message: 'The fieldset type is missing' + ); } $this->type = $params['id'] = $params['type']; diff --git a/src/Cms/File.php b/src/Cms/File.php index 4dbce31dca..cb042a8044 100644 --- a/src/Cms/File.php +++ b/src/Cms/File.php @@ -82,7 +82,9 @@ class File extends ModelWithContent public function __construct(array $props) { if (isset($props['filename'], $props['parent']) === false) { - throw new InvalidArgumentException('The filename and parent are required'); + throw new InvalidArgumentException( + message: 'The filename and parent are required' + ); } $this->filename = $props['filename']; diff --git a/src/Cms/FileActions.php b/src/Cms/FileActions.php index d1b08e4089..1338393d87 100644 --- a/src/Cms/FileActions.php +++ b/src/Cms/FileActions.php @@ -76,7 +76,9 @@ public function changeName( } if ($newFile->exists() === true) { - throw new LogicException('The new file exists and cannot be overwritten'); + throw new LogicException( + message: 'The new file exists and cannot be overwritten' + ); } // rename the main file @@ -246,7 +248,9 @@ public function copy(Page $page): static public static function create(array $props, bool $move = false): File { if (isset($props['source'], $props['parent']) === false) { - throw new InvalidArgumentException('Please provide the "source" and "parent" props for the File'); + throw new InvalidArgumentException( + message: 'Please provide the "source" and "parent" props for the File' + ); } // prefer the filename from the props @@ -306,7 +310,9 @@ public static function create(array $props, bool $move = false): File // overwrite the original if (F::$method($upload->root(), $file->root(), true) !== true) { - throw new LogicException('The file could not be created'); + throw new LogicException( + message: 'The file could not be created' + ); } // resize the file on upload if configured @@ -407,7 +413,9 @@ public function replace(string $source, bool $move = false): static // overwrite the original if (F::$method($upload->root(), $file->root(), true) !== true) { - throw new LogicException('The file could not be created'); + throw new LogicException( + message: 'The file could not be created' + ); } // apply the resizing/crop options from the blueprint diff --git a/src/Cms/FileModifications.php b/src/Cms/FileModifications.php index a4f481d5ee..b07de97783 100644 --- a/src/Cms/FileModifications.php +++ b/src/Cms/FileModifications.php @@ -207,7 +207,9 @@ public function thumb( $result instanceof File === false && $result instanceof Asset === false ) { - throw new InvalidArgumentException('The file::version component must return a File, FileVersion or Asset object'); + throw new InvalidArgumentException( + message: 'The file::version component must return a File, FileVersion or Asset object' + ); } return $result; diff --git a/src/Cms/FilePicker.php b/src/Cms/FilePicker.php index f1d20b8518..0ed91bf376 100644 --- a/src/Cms/FilePicker.php +++ b/src/Cms/FilePicker.php @@ -59,7 +59,9 @@ public function items(): Files|null $files instanceof User => $files->files(), $files instanceof Files => $files, - default => throw new InvalidArgumentException('Your query must return a set of files') + default => throw new InvalidArgumentException( + message: 'Your query must return a set of files' + ) }; // filter protected and hidden pages diff --git a/src/Cms/FileRules.php b/src/Cms/FileRules.php index 00b1223693..403fd3fe7a 100644 --- a/src/Cms/FileRules.php +++ b/src/Cms/FileRules.php @@ -135,7 +135,9 @@ public static function create(File $file, BaseFile $upload): void } if ($file->permissions()->create() !== true) { - throw new PermissionException('The file cannot be created'); + throw new PermissionException( + message: 'The file cannot be created' + ); } static::validFile($file, $upload->mime()); @@ -152,7 +154,9 @@ public static function create(File $file, BaseFile $upload): void public static function delete(File $file): void { if ($file->permissions()->delete() !== true) { - throw new PermissionException('The file cannot be deleted'); + throw new PermissionException( + message: 'The file cannot be deleted' + ); } } @@ -165,7 +169,9 @@ public static function delete(File $file): void public static function replace(File $file, BaseFile $upload): void { if ($file->permissions()->replace() !== true) { - throw new PermissionException('The file cannot be replaced'); + throw new PermissionException( + message: 'The file cannot be replaced' + ); } static::validMime($file, $upload->mime()); @@ -192,7 +198,9 @@ public static function replace(File $file, BaseFile $upload): void public static function update(File $file, array $content = []): void { if ($file->permissions()->update() !== true) { - throw new PermissionException('The file cannot be updated'); + throw new PermissionException( + message: 'The file cannot be updated' + ); } } diff --git a/src/Cms/Files.php b/src/Cms/Files.php index 61e644d74f..f935bf9303 100644 --- a/src/Cms/Files.php +++ b/src/Cms/Files.php @@ -65,7 +65,9 @@ public function add($object): static // give a useful error message on invalid input; // silently ignore "empty" values for compatibility with existing setups } elseif (in_array($object, [null, false, true], true) !== true) { - throw new InvalidArgumentException('You must pass a Files or File object or an ID of an existing file to the Files collection'); + throw new InvalidArgumentException( + message: 'You must pass a Files or File object or an ID of an existing file to the Files collection' + ); } return $this; diff --git a/src/Cms/HasMethods.php b/src/Cms/HasMethods.php index 9e08d5b0b8..4903782599 100644 --- a/src/Cms/HasMethods.php +++ b/src/Cms/HasMethods.php @@ -33,7 +33,9 @@ public function callMethod(string $method, array $args = []): mixed $closure = $this->getMethod($method); if ($closure === null) { - throw new BadMethodCallException('The method ' . $method . ' does not exist'); + throw new BadMethodCallException( + message: 'The method ' . $method . ' does not exist' + ); } return $closure->call($this, ...$args); diff --git a/src/Cms/Helpers.php b/src/Cms/Helpers.php index 08fd5f1f7b..895c579cac 100644 --- a/src/Cms/Helpers.php +++ b/src/Cms/Helpers.php @@ -196,6 +196,8 @@ public static function size(mixed $value): int return count($value); } - throw new InvalidArgumentException('Could not determine the size of the given value'); + throw new InvalidArgumentException( + message: 'Could not determine the size of the given value' + ); } } diff --git a/src/Cms/Items.php b/src/Cms/Items.php index 8aa42b442a..7cc56ab0b0 100644 --- a/src/Cms/Items.php +++ b/src/Cms/Items.php @@ -59,7 +59,7 @@ public static function factory( } if (is_array($params) === false) { - throw new InvalidArgumentException('Invalid item options'); + throw new InvalidArgumentException(message: 'Invalid item options'); } // create a new collection of blocks @@ -67,7 +67,9 @@ public static function factory( foreach ($items as $item) { if (is_array($item) === false) { - throw new InvalidArgumentException('Invalid data for ' . static::ITEM_CLASS); + throw new InvalidArgumentException( + message: 'Invalid data for ' . static::ITEM_CLASS + ); } // inject properties from the parent diff --git a/src/Cms/Language.php b/src/Cms/Language.php index a8be660bdc..d5265c2c79 100644 --- a/src/Cms/Language.php +++ b/src/Cms/Language.php @@ -57,7 +57,9 @@ class Language implements Stringable public function __construct(array $props) { if (isset($props['code']) === false) { - throw new InvalidArgumentException('The property "code" is required'); + throw new InvalidArgumentException( + message: 'The property "code" is required' + ); } static::$kirby = $props['kirby'] ?? null; @@ -232,7 +234,7 @@ public function delete(): bool LanguageRules::delete($language); if (F::remove($language->root()) !== true) { - throw new Exception('The language could not be deleted'); + throw new Exception(message: 'The language could not be deleted'); } // if needed, convert content storage to single lang @@ -288,7 +290,7 @@ public static function ensure(self|string|null $code = null): static } // validate the language code - throw new NotFoundException('Invalid language: ' . $code); + throw new NotFoundException(message: 'Invalid language: ' . $code); } /** diff --git a/src/Cms/LanguageRouter.php b/src/Cms/LanguageRouter.php index 2f73b7f37b..550766d9c7 100644 --- a/src/Cms/LanguageRouter.php +++ b/src/Cms/LanguageRouter.php @@ -80,7 +80,9 @@ public function routes(): array $routes[$index]['pattern'] = $patterns; $routes[$index]['page'] = $page; } else { - throw new NotFoundException('The page "' . $pageId . '" does not exist'); + throw new NotFoundException( + message: 'The page "' . $pageId . '" does not exist' + ); } } } diff --git a/src/Cms/LanguageVariable.php b/src/Cms/LanguageVariable.php index 7ca846bf87..94e5fe0d23 100644 --- a/src/Cms/LanguageVariable.php +++ b/src/Cms/LanguageVariable.php @@ -37,11 +37,15 @@ public static function create( string|null $value = null ): static { if (is_numeric($key) === true) { - throw new InvalidArgumentException('The variable key must not be numeric'); + throw new InvalidArgumentException( + message: 'The variable key must not be numeric' + ); } if (empty($key) === true) { - throw new InvalidArgumentException('The variable needs a valid key'); + throw new InvalidArgumentException( + message: 'The variable needs a valid key' + ); } $kirby = App::instance(); @@ -50,10 +54,14 @@ public static function create( if ($kirby->translation()->get($key) !== null) { if (isset($translations[$key]) === true) { - throw new DuplicateException('The variable already exists'); + throw new DuplicateException( + message: 'The variable already exists' + ); } - throw new DuplicateException('The variable is part of the core translation and cannot be overwritten'); + throw new DuplicateException( + message: 'The variable is part of the core translation and cannot be overwritten' + ); } $translations[$key] = $value ?? ''; diff --git a/src/Cms/Languages.php b/src/Cms/Languages.php index bf1f008005..53ea618c7b 100644 --- a/src/Cms/Languages.php +++ b/src/Cms/Languages.php @@ -39,7 +39,9 @@ public function __construct( ); if (count($defaults) > 1) { - throw new DuplicateException('You cannot have multiple default languages. Please check your language config files.'); + throw new DuplicateException( + message: 'You cannot have multiple default languages. Please check your language config files.' + ); } parent::__construct($objects, null); diff --git a/src/Cms/Media.php b/src/Cms/Media.php index 8150201e8d..a672beabbd 100644 --- a/src/Cms/Media.php +++ b/src/Cms/Media.php @@ -115,11 +115,15 @@ public static function thumb( $options = Data::read($job); } catch (Throwable) { // send a customized error message to make clearer what happened here - throw new NotFoundException('The thumbnail configuration could not be found'); + throw new NotFoundException( + message: 'The thumbnail configuration could not be found' + ); } if (empty($options['filename']) === true) { - throw new InvalidArgumentException('Incomplete thumbnail configuration'); + throw new InvalidArgumentException( + message: 'Incomplete thumbnail configuration' + ); } try { diff --git a/src/Cms/ModelWithContent.php b/src/Cms/ModelWithContent.php index 720b870bd8..9911c44d4e 100644 --- a/src/Cms/ModelWithContent.php +++ b/src/Cms/ModelWithContent.php @@ -475,7 +475,9 @@ protected function saveTranslation( $translation = $clone->translation($languageCode); if ($translation === null) { - throw new InvalidArgumentException('Invalid language: ' . $languageCode); + throw new InvalidArgumentException( + message: 'Invalid language: ' . $languageCode + ); } // get the content to store @@ -612,7 +614,7 @@ public function toString( } if ($handler !== 'template' && $handler !== 'safeTemplate') { - throw new InvalidArgumentException('Invalid toString handler'); // @codeCoverageIgnore + throw new InvalidArgumentException(message: 'Invalid toString handler'); // @codeCoverageIgnore } $result = Str::$handler($template, array_replace([ diff --git a/src/Cms/PagePicker.php b/src/Cms/PagePicker.php index c09617e4f6..7c4dda8fac 100644 --- a/src/Cms/PagePicker.php +++ b/src/Cms/PagePicker.php @@ -179,7 +179,9 @@ public function itemsForQuery(): Pages $items instanceof Page => $items->children(), $items instanceof Pages => $items, - default => throw new InvalidArgumentException('Your query must return a set of pages') + default => throw new InvalidArgumentException( + message: 'Your query must return a set of pages' + ) }; return $this->itemsForQuery = $items; diff --git a/src/Cms/Pages.php b/src/Cms/Pages.php index 14feae51ac..4443e431ac 100644 --- a/src/Cms/Pages.php +++ b/src/Cms/Pages.php @@ -78,7 +78,9 @@ public function add($object): static // give a useful error message on invalid input; // silently ignore "empty" values for compatibility with existing setups } elseif (in_array($object, [null, false, true], true) !== true) { - throw new InvalidArgumentException('You must pass a Pages or Page object or an ID of an existing page to the Pages collection'); + throw new InvalidArgumentException( + message: 'You must pass a Pages or Page object or an ID of an existing page to the Pages collection' + ); } return $this; diff --git a/src/Cms/Permissions.php b/src/Cms/Permissions.php index c16ac88cf9..a89ff22a49 100644 --- a/src/Cms/Permissions.php +++ b/src/Cms/Permissions.php @@ -96,7 +96,9 @@ public function __construct(array|bool|null $settings = []) // dynamically register the extended actions foreach (static::$extendedActions as $key => $actions) { if (isset($this->actions[$key]) === true) { - throw new InvalidArgumentException('The action ' . $key . ' is already a core action'); + throw new InvalidArgumentException( + message: 'The action ' . $key . ' is already a core action' + ); } $this->actions[$key] = $actions; @@ -200,7 +202,9 @@ protected function setCategories(array $settings): static protected function setCategory(string $category, bool $setting): static { if ($this->hasCategory($category) === false) { - throw new InvalidArgumentException('Invalid permissions category'); + throw new InvalidArgumentException( + message: 'Invalid permissions category' + ); } foreach ($this->actions[$category] as $action => $actionSetting) { diff --git a/src/Cms/Plugin.php b/src/Cms/Plugin.php index 79b8d24125..8536afb7f9 100644 --- a/src/Cms/Plugin.php +++ b/src/Cms/Plugin.php @@ -296,7 +296,9 @@ public function updateStatus(array|null $data = null): UpdateStatus|null public static function validateName(string $name): void { if (preg_match('!^[a-z0-9-]+\/[a-z0-9-]+$!i', $name) !== 1) { - throw new InvalidArgumentException('The plugin name must follow the format "a-z0-9-/a-z0-9-"'); + throw new InvalidArgumentException( + message: 'The plugin name must follow the format "a-z0-9-/a-z0-9-"' + ); } } diff --git a/src/Cms/Responder.php b/src/Cms/Responder.php index 899b108881..c6294c6932 100644 --- a/src/Cms/Responder.php +++ b/src/Cms/Responder.php @@ -188,7 +188,9 @@ public function expires($expires = null, bool $override = false) $parsedExpires = strtotime($expires); if (is_int($parsedExpires) !== true) { - throw new InvalidArgumentException('Invalid time string "' . $expires . '"'); + throw new InvalidArgumentException( + message: 'Invalid time string "' . $expires . '"' + ); } $expires = $parsedExpires; diff --git a/src/Cms/Section.php b/src/Cms/Section.php index 133b74ebf5..a1785d32ef 100644 --- a/src/Cms/Section.php +++ b/src/Cms/Section.php @@ -33,11 +33,15 @@ class Section extends Component public function __construct(string $type, array $attrs = []) { if (isset($attrs['model']) === false) { - throw new InvalidArgumentException('Undefined section model'); + throw new InvalidArgumentException( + message: 'Undefined section model' + ); } if ($attrs['model'] instanceof ModelWithContent === false) { - throw new InvalidArgumentException('Invalid section model'); + throw new InvalidArgumentException( + message: 'Invalid section model' + ); } // use the type as fallback for the name diff --git a/src/Cms/Site.php b/src/Cms/Site.php index 6a97d4d078..e9c3142c32 100644 --- a/src/Cms/Site.php +++ b/src/Cms/Site.php @@ -470,7 +470,7 @@ public function visit( // handle invalid pages if ($page instanceof Page === false) { - throw new InvalidArgumentException('Invalid page object'); + throw new InvalidArgumentException(message: 'Invalid page object'); } // set and return the current active page diff --git a/src/Cms/System.php b/src/Cms/System.php index 3de3b2f091..b1bd36edc3 100644 --- a/src/Cms/System.php +++ b/src/Cms/System.php @@ -190,28 +190,36 @@ public function init(): void try { Dir::make($this->app->root('accounts')); } catch (Throwable) { - throw new PermissionException('The accounts directory could not be created'); + throw new PermissionException( + message: 'The accounts directory could not be created' + ); } // init /site/sessions try { Dir::make($this->app->root('sessions')); } catch (Throwable) { - throw new PermissionException('The sessions directory could not be created'); + throw new PermissionException( + message: 'The sessions directory could not be created' + ); } // init /content try { Dir::make($this->app->root('content')); } catch (Throwable) { - throw new PermissionException('The content directory could not be created'); + throw new PermissionException( + message: 'The content directory could not be created' + ); } // init /media try { Dir::make($this->app->root('media')); } catch (Throwable) { - throw new PermissionException('The media directory could not be created'); + throw new PermissionException( + message: 'The media directory could not be created' + ); } } diff --git a/src/Cms/UserActions.php b/src/Cms/UserActions.php index 57558458e2..c667561791 100644 --- a/src/Cms/UserActions.php +++ b/src/Cms/UserActions.php @@ -162,7 +162,9 @@ protected function commit( Closure $callback ): mixed { if ($this->isKirby() === true) { - throw new PermissionException('The Kirby user cannot be changed'); + throw new PermissionException( + message: 'The Kirby user cannot be changed' + ); } $kirby = $this->kirby(); @@ -302,7 +304,9 @@ public function delete(): bool // delete the user directory if (Dir::remove($user->root()) !== true) { - throw new LogicException('The user directory for "' . $user->email() . '" could not be deleted'); + throw new LogicException( + message: 'The user directory for "' . $user->email() . '" could not be deleted' + ); } // remove the user from users collection diff --git a/src/Cms/UserPicker.php b/src/Cms/UserPicker.php index dadc1752b6..c79b775201 100644 --- a/src/Cms/UserPicker.php +++ b/src/Cms/UserPicker.php @@ -52,7 +52,9 @@ public function items(): Users|null // catch invalid data if ($users instanceof Users === false) { - throw new InvalidArgumentException('Your query must return a set of users'); + throw new InvalidArgumentException( + message: 'Your query must return a set of users' + ); } // search & sort diff --git a/src/Cms/UserRules.php b/src/Cms/UserRules.php index 250f0f78f3..a19f81018d 100644 --- a/src/Cms/UserRules.php +++ b/src/Cms/UserRules.php @@ -287,12 +287,14 @@ public static function validId(User $user, string $id): void { if (in_array($id, ['account', 'kirby', 'nobody'], true) === true) { throw new InvalidArgumentException( - '"' . $id . '" is a reserved word and cannot be used as user id' + message: '"' . $id . '" is a reserved word and cannot be used as user id' ); } if ($user->kirby()->users()->find($id)) { - throw new DuplicateException('A user with this id exists'); + throw new DuplicateException( + message: 'A user with this id exists' + ); } } diff --git a/src/Cms/Users.php b/src/Cms/Users.php index da254021aa..c67d1fe11f 100644 --- a/src/Cms/Users.php +++ b/src/Cms/Users.php @@ -65,7 +65,9 @@ public function add($object): static // give a useful error message on invalid input; // silently ignore "empty" values for compatibility with existing setups } elseif (in_array($object, [null, false, true], true) !== true) { - throw new InvalidArgumentException('You must pass a Users or User object or an ID of an existing user to the Users collection'); + throw new InvalidArgumentException( + message: 'You must pass a Users or User object or an ID of an existing user to the Users collection' + ); } return $this; diff --git a/src/Content/ImmutableMemoryContentStorageHandler.php b/src/Content/ImmutableMemoryContentStorageHandler.php index 64b5f25d81..8ae7cf77a1 100644 --- a/src/Content/ImmutableMemoryContentStorageHandler.php +++ b/src/Content/ImmutableMemoryContentStorageHandler.php @@ -35,7 +35,9 @@ public function move( */ protected function preventMutation(): void { - throw new LogicException('Storage for the ' . $this->model::CLASS_ALIAS . ' is immutable and cannot be deleted. Make sure to use the last alteration of the object.'); + throw new LogicException( + message: 'Storage for the ' . $this->model::CLASS_ALIAS . ' is immutable and cannot be deleted. Make sure to use the last alteration of the object.' + ); } public function touch(VersionId $versionId, Language $language): void diff --git a/src/Content/PlainTextContentStorageHandler.php b/src/Content/PlainTextContentStorageHandler.php index a952bef606..cdddaeef59 100644 --- a/src/Content/PlainTextContentStorageHandler.php +++ b/src/Content/PlainTextContentStorageHandler.php @@ -59,7 +59,9 @@ public function contentFile(VersionId $versionId, Language $language): string $this->model instanceof Site => $this->contentFileForSite($this->model, $versionId, $language), $this->model instanceof User => $this->contentFileForUser($this->model, $versionId, $language), // @codeCoverageIgnoreStart - default => throw new LogicException('Cannot determine content file for model type "' . $this->model::CLASS_ALIAS . '"') + default => throw new LogicException( + message: 'Cannot determine content file for model type "' . $this->model::CLASS_ALIAS . '"' + ) // @codeCoverageIgnoreEnd }; } @@ -138,7 +140,7 @@ public function delete(VersionId $versionId, Language $language): void // @codeCoverageIgnoreStart if (F::unlink($contentFile) !== true) { - throw new Exception('Could not delete content file'); + throw new Exception(message: 'Could not delete content file'); } // @codeCoverageIgnoreEnd @@ -161,7 +163,9 @@ protected function deleteEmptyDirectory(string $directory): void ) { // @codeCoverageIgnoreStart if (Dir::remove($directory) !== true) { - throw new Exception('Could not delete empty content directory'); + throw new Exception( + message: 'Could not delete empty content directory' + ); } // @codeCoverageIgnoreEnd } @@ -196,7 +200,9 @@ public function exists(VersionId $versionId, Language $language): bool $this->model instanceof Site, $this->model instanceof User => is_dir($this->model->root()) === true, // @codeCoverageIgnoreStart - default => throw new LogicException('Cannot determine existance for model type "' . $this->model::CLASS_ALIAS . '"') + default => throw new LogicException( + message: 'Cannot determine existence for model type "' . $this->model::CLASS_ALIAS . '"' + ) // @codeCoverageIgnoreEnd }; } @@ -279,7 +285,9 @@ public function touch(VersionId $versionId, Language $language): void // @codeCoverageIgnoreStart if ($success !== true) { - throw new Exception('Could not touch existing content file'); + throw new Exception( + message: 'Could not touch existing content file' + ); } // @codeCoverageIgnoreEnd } @@ -297,7 +305,7 @@ protected function write(VersionId $versionId, Language $language, array $fields // @codeCoverageIgnoreStart if ($success !== true) { - throw new Exception('Could not write the content file'); + throw new Exception(message: 'Could not write the content file'); } // @codeCoverageIgnoreEnd } diff --git a/src/Content/Version.php b/src/Content/Version.php index 7278a21d07..e8a5cbe9d5 100644 --- a/src/Content/Version.php +++ b/src/Content/Version.php @@ -237,7 +237,9 @@ protected function prepareFieldsAfterRead(array $fields, Language $language): ar public function publish(Language|string $language = 'default'): void { if ($this->id->value() === VersionId::PUBLISHED) { - throw new LogicException('This version is already published'); + throw new LogicException( + message: 'This version is already published' + ); } $language = Language::ensure($language); diff --git a/src/Content/VersionId.php b/src/Content/VersionId.php index f1e8632d72..8b40dbf715 100644 --- a/src/Content/VersionId.php +++ b/src/Content/VersionId.php @@ -45,7 +45,7 @@ public function __construct( public string $value ) { if (in_array($value, [static::CHANGES, static::PUBLISHED], true) === false) { - throw new InvalidArgumentException('Invalid Version ID'); + throw new InvalidArgumentException(message: 'Invalid Version ID'); } } diff --git a/src/Data/Json.php b/src/Data/Json.php index 35fa867041..6fcb74e158 100644 --- a/src/Data/Json.php +++ b/src/Data/Json.php @@ -40,7 +40,9 @@ public static function decode($string): array } if (is_string($string) === false) { - throw new InvalidArgumentException('Invalid JSON data; please pass a string'); + throw new InvalidArgumentException( + message: 'Invalid JSON data; please pass a string' + ); } $result = json_decode($string, true); @@ -49,6 +51,8 @@ public static function decode($string): array return $result; } - throw new InvalidArgumentException('JSON string is invalid'); + throw new InvalidArgumentException( + message: 'JSON string is invalid' + ); } } diff --git a/src/Data/Txt.php b/src/Data/Txt.php index ae6fbf2b47..cd0e886f7e 100644 --- a/src/Data/Txt.php +++ b/src/Data/Txt.php @@ -89,7 +89,9 @@ public static function decode($string): array } if (is_string($string) === false) { - throw new InvalidArgumentException('Invalid TXT data; please pass a string'); + throw new InvalidArgumentException( + message: 'Invalid TXT data; please pass a string' + ); } // remove Unicode BOM at the beginning of the file diff --git a/src/Data/Xml.php b/src/Data/Xml.php index 68fa51158d..63d6054888 100644 --- a/src/Data/Xml.php +++ b/src/Data/Xml.php @@ -38,7 +38,9 @@ public static function decode($string): array } if (is_string($string) === false) { - throw new InvalidArgumentException('Invalid XML data; please pass a string'); + throw new InvalidArgumentException( + message: 'Invalid XML data; please pass a string' + ); } $result = XmlConverter::parse($string); @@ -53,6 +55,6 @@ public static function decode($string): array return $result; } - throw new InvalidArgumentException('XML string is invalid'); + throw new InvalidArgumentException(message: 'XML string is invalid'); } } diff --git a/src/Data/Yaml.php b/src/Data/Yaml.php index efa9c9cdd0..175bb69062 100644 --- a/src/Data/Yaml.php +++ b/src/Data/Yaml.php @@ -41,7 +41,9 @@ public static function decode($string): array } if (is_string($string) === false) { - throw new InvalidArgumentException('Invalid YAML data; please pass a string'); + throw new InvalidArgumentException( + message: 'Invalid YAML data; please pass a string' + ); } return match (static::handler()) { diff --git a/src/Data/YamlSpyc.php b/src/Data/YamlSpyc.php index a00e92d8c2..cd51e1b499 100644 --- a/src/Data/YamlSpyc.php +++ b/src/Data/YamlSpyc.php @@ -38,6 +38,6 @@ public static function decode($string): array // apparently Spyc always returns an array, even for invalid YAML syntax // so this Exception should currently never be thrown - throw new InvalidArgumentException('The YAML data cannot be parsed'); // @codeCoverageIgnore + throw new InvalidArgumentException(message: 'The YAML data cannot be parsed'); // @codeCoverageIgnore } } diff --git a/src/Database/Database.php b/src/Database/Database.php index aaadad3db7..eb2f4ccbc7 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -162,7 +162,9 @@ public function connect(array|null $params = null): PDO|null $this->id = $options['id']; if (isset(static::$types[$this->type]) === false) { - throw new InvalidArgumentException('Invalid database type: ' . $this->type); + throw new InvalidArgumentException( + message: 'Invalid database type: ' . $this->type + ); } // fetch the dsn and store it @@ -559,11 +561,15 @@ public function __call(string $method, mixed $arguments = null): Query isset($params['host']) === false && isset($params['socket']) === false ) { - throw new InvalidArgumentException('The mysql connection requires either a "host" or a "socket" parameter'); + throw new InvalidArgumentException( + message: 'The mysql connection requires either a "host" or a "socket" parameter' + ); } if (isset($params['database']) === false) { - throw new InvalidArgumentException('The mysql connection requires a "database" parameter'); + throw new InvalidArgumentException( + message: 'The mysql connection requires a "database" parameter' + ); } $parts = []; @@ -597,7 +603,9 @@ public function __call(string $method, mixed $arguments = null): Query 'sql' => Sqlite::class, 'dsn' => function (array $params): string { if (isset($params['database']) === false) { - throw new InvalidArgumentException('The sqlite connection requires a "database" parameter'); + throw new InvalidArgumentException( + message: 'The sqlite connection requires a "database" parameter' + ); } return 'sqlite:' . $params['database']; diff --git a/src/Database/Db.php b/src/Database/Db.php index 82d07b5013..d7d5c40310 100644 --- a/src/Database/Db.php +++ b/src/Database/Db.php @@ -112,7 +112,9 @@ public static function __callStatic(string $method, $arguments) return call_user_func_array([static::$connection, $method], $arguments); } - throw new InvalidArgumentException('Invalid static Db method: ' . $method); + throw new InvalidArgumentException( + message: 'Invalid static Db method: ' . $method + ); } } diff --git a/src/Database/Query.php b/src/Database/Query.php index b3ba452d60..659d1d984f 100644 --- a/src/Database/Query.php +++ b/src/Database/Query.php @@ -208,7 +208,9 @@ public function iterator(string $iterator): static public function table(string $table): static { if ($this->database->validateTable($table) === false) { - throw new InvalidArgumentException('Invalid table: ' . $table); + throw new InvalidArgumentException( + message: 'Invalid table: ' . $table + ); } $this->table = $table; @@ -810,7 +812,10 @@ public function __call(string $method, array $arguments = []) return $this->findBy($column, $arguments[0]); } - throw new InvalidArgumentException('Invalid query method: ' . $method, static::ERROR_INVALID_QUERY_METHOD); + throw new InvalidArgumentException( + message: 'Invalid query method: ' . $method, + code: static::ERROR_INVALID_QUERY_METHOD + ); } /** @@ -906,7 +911,9 @@ protected function filterQuery( $predicate = trim(strtoupper($args[1])); if (is_array($args[2]) === true) { if (in_array($predicate, ['IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'], true) === false) { - throw new InvalidArgumentException('Invalid predicate ' . $predicate); + throw new InvalidArgumentException( + message: 'Invalid predicate ' . $predicate + ); } // build a list of bound values @@ -939,7 +946,9 @@ protected function filterQuery( ]; if (in_array($predicate, $predicates, true) === false) { - throw new InvalidArgumentException('Invalid predicate/operator ' . $predicate); + throw new InvalidArgumentException( + message: 'Invalid predicate/operator ' . $predicate + ); } $valueBinding = $sql->bindingName('value'); diff --git a/src/Database/Sql.php b/src/Database/Sql.php index 1877f4caab..08dfcd10d7 100644 --- a/src/Database/Sql.php +++ b/src/Database/Sql.php @@ -180,13 +180,17 @@ public function createColumn(string $name, array $column): array { // column type if (isset($column['type']) === false) { - throw new InvalidArgumentException('No column type given for column ' . $name); + throw new InvalidArgumentException( + message: 'No column type given for column ' . $name + ); } $template = $this->columnTypes()[$column['type']] ?? null; if (!$template) { - throw new InvalidArgumentException('Unsupported column type: ' . $column['type']); + throw new InvalidArgumentException( + message: 'Unsupported column type: ' . $column['type'] + ); } // null option @@ -476,7 +480,9 @@ public function join(string $type, string $table, string $on): array // validate join type if (in_array($type, $types, true) === false) { - throw new InvalidArgumentException('Invalid join type ' . $type); + throw new InvalidArgumentException( + message: 'Invalid join type ' . $type + ); } return [ @@ -690,7 +696,9 @@ public function splitIdentifier(string $table, string $identifier): array ], // every other number is an error - default => throw new InvalidArgumentException('Invalid identifier ' . $identifier) + default => throw new InvalidArgumentException( + message: 'Invalid identifier ' . $identifier + ) }; } @@ -709,7 +717,9 @@ public function tableName(string $table): string { // validate table if ($this->database->validateTable($table) === false) { - throw new InvalidArgumentException('Invalid table ' . $table); + throw new InvalidArgumentException( + message: 'Invalid table ' . $table + ); } return $this->quoteIdentifier($table); @@ -787,7 +797,9 @@ public function update(array $params = []): array public function validateColumn(string $table, string $column): bool { if ($this->database->validateColumn($table, $column) !== true) { - throw new InvalidArgumentException('Invalid column ' . $column); + throw new InvalidArgumentException( + message: 'Invalid column ' . $column + ); } return true; diff --git a/src/Email/Email.php b/src/Email/Email.php index 2f1b15f3d4..0558d62079 100644 --- a/src/Email/Email.php +++ b/src/Email/Email.php @@ -53,7 +53,9 @@ public function __construct(array $props = [], bool $debug = false) { foreach (['body', 'from', 'to', 'subject'] as $required) { if (isset($props[$required]) === false) { - throw new InvalidArgumentException('The property "' . $required . '" is required'); + throw new InvalidArgumentException( + message: 'The property "' . $required . '" is required' + ); } } diff --git a/src/Email/PHPMailer.php b/src/Email/PHPMailer.php index ee84a40405..c04b36ef7c 100644 --- a/src/Email/PHPMailer.php +++ b/src/Email/PHPMailer.php @@ -99,7 +99,9 @@ public function send(bool $debug = false): bool $mailer = $beforeSend->call($this, $mailer) ?? $mailer; if ($mailer instanceof Mailer === false) { - throw new InvalidArgumentException('"beforeSend" option return should be instance of PHPMailer\PHPMailer\PHPMailer class'); + throw new InvalidArgumentException( + message: '"beforeSend" option return should be instance of PHPMailer\PHPMailer\PHPMailer class' + ); } } diff --git a/src/Filesystem/Asset.php b/src/Filesystem/Asset.php index d0214ccf2d..7f727fd997 100644 --- a/src/Filesystem/Asset.php +++ b/src/Filesystem/Asset.php @@ -68,7 +68,9 @@ public function __call(string $method, array $arguments = []): mixed return $this->callMethod($method, $arguments); } - throw new BadMethodCallException('The method: "' . $method . '" does not exist'); + throw new BadMethodCallException( + message: 'The method: "' . $method . '" does not exist' + ); } /** diff --git a/src/Filesystem/IsFile.php b/src/Filesystem/IsFile.php index e5b1ab12d9..01ee56bd6b 100644 --- a/src/Filesystem/IsFile.php +++ b/src/Filesystem/IsFile.php @@ -62,7 +62,9 @@ public function __call(string $method, array $arguments = []): mixed return $this->asset()->$method(...$arguments); } - throw new BadMethodCallException('The method: "' . $method . '" does not exist'); + throw new BadMethodCallException( + message: 'The method: "' . $method . '" does not exist' + ); } /** diff --git a/src/Form/Field.php b/src/Form/Field.php index 275665f77a..02807834aa 100644 --- a/src/Form/Field.php +++ b/src/Form/Field.php @@ -63,7 +63,9 @@ public function __construct( } if (isset($attrs['model']) === false) { - throw new InvalidArgumentException('Field requires a model'); + throw new InvalidArgumentException( + message: 'Field requires a model' + ); } $this->formFields = $formFields; diff --git a/src/Form/Form.php b/src/Form/Form.php index 9629309faa..9065552021 100644 --- a/src/Form/Form.php +++ b/src/Form/Form.php @@ -208,12 +208,16 @@ public function field(string $name): Field|FieldClass continue; } - throw new NotFoundException('The field "' . $fieldName . '" could not be found'); + throw new NotFoundException( + message: 'The field "' . $fieldName . '" could not be found' + ); } // it can get this error only if $name is an empty string as $name = '' if ($field === null) { - throw new NotFoundException('No field could be loaded'); + throw new NotFoundException( + message: 'No field could be loaded' + ); } return $field; diff --git a/src/Http/Environment.php b/src/Http/Environment.php index f90559ed2f..2339cb5aca 100644 --- a/src/Http/Environment.php +++ b/src/Http/Environment.php @@ -211,7 +211,9 @@ protected function detectAllowed(array|string $allowed): void $baseUrl = A::first($allowed); if (is_string($baseUrl) === false) { - throw new InvalidArgumentException('Invalid allow list setup for base URLs'); + throw new InvalidArgumentException( + message: 'Invalid allow list setup for base URLs' + ); } $uri = new Uri($baseUrl, ['slash' => false]); @@ -248,7 +250,9 @@ protected function detectAllowed(array|string $allowed): void } } - throw new InvalidArgumentException('The environment is not allowed'); + throw new InvalidArgumentException( + message: 'The environment is not allowed' + ); } /** diff --git a/src/Http/Remote.php b/src/Http/Remote.php index ac5bd54f28..6f2733bda7 100644 --- a/src/Http/Remote.php +++ b/src/Http/Remote.php @@ -171,7 +171,9 @@ public function fetch(): static $this->curlopt[CURLOPT_SSL_VERIFYPEER] = true; $this->curlopt[CURLOPT_CAPATH] = $this->options['ca']; } else { - throw new InvalidArgumentException('Invalid "ca" option for the Remote class'); + throw new InvalidArgumentException( + message: 'Invalid "ca" option for the Remote class' + ); } // add the progress diff --git a/src/Http/Response.php b/src/Http/Response.php index 385a381776..a79393f2c9 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -135,7 +135,7 @@ public static function download( array $props = [] ): static { if (file_exists($file) === false) { - throw new Exception('The file could not be found'); + throw new Exception(message: 'The file could not be found'); } $filename ??= basename($file); diff --git a/src/Http/Route.php b/src/Http/Route.php index 842d00e329..863908b5fd 100644 --- a/src/Http/Route.php +++ b/src/Http/Route.php @@ -131,7 +131,7 @@ public function name(): string|null */ public static function next(): void { - throw new Exceptions\NextRouteException('next'); + throw new Exceptions\NextRouteException(message: 'next'); } /** diff --git a/src/Http/Router.php b/src/Http/Router.php index f7165530be..5a9be205ff 100644 --- a/src/Http/Router.php +++ b/src/Http/Router.php @@ -63,7 +63,9 @@ public function __construct(array $routes = [], array $hooks = []) foreach ($routes as $props) { if (isset($props['pattern'], $props['action']) === false) { - throw new InvalidArgumentException('Invalid route parameters'); + throw new InvalidArgumentException( + message: 'Invalid route parameters' + ); } $patterns = A::wrap($props['pattern']); @@ -163,7 +165,10 @@ public function find( array|null $ignore = null ): Route { if (isset($this->routes[$method]) === false) { - throw new InvalidArgumentException('Invalid routing method: ' . $method, 400); + throw new InvalidArgumentException( + message: 'Invalid routing method: ' . $method, + code: 400 + ); } // remove leading and trailing slashes @@ -182,7 +187,10 @@ public function find( } } - throw new Exception('No route found for path: "' . $path . '" and request method: "' . $method . '"', 404); + throw new Exception( + code: 404, + message: 'No route found for path: "' . $path . '" and request method: "' . $method . '"', + ); } /** diff --git a/src/Http/Uri.php b/src/Http/Uri.php index 6a8275ab69..75d71938af 100644 --- a/src/Http/Uri.php +++ b/src/Http/Uri.php @@ -374,7 +374,9 @@ public function setPort(int|null $port = null): static if ($port !== null) { if ($port < 1 || $port > 65535) { - throw new InvalidArgumentException('Invalid port format: ' . $port); + throw new InvalidArgumentException( + message: 'Invalid port format: ' . $port + ); } } @@ -396,8 +398,13 @@ public function setQuery(Query|string|array|null $query = null): static */ public function setScheme(string|null $scheme = null): static { - if ($scheme !== null && in_array($scheme, static::$schemes, true) === false) { - throw new InvalidArgumentException('Invalid URL scheme: ' . $scheme); + if ( + $scheme !== null && + in_array($scheme, static::$schemes, true) === false + ) { + throw new InvalidArgumentException( + message: 'Invalid URL scheme: ' . $scheme + ); } $this->scheme = $scheme; diff --git a/src/Image/Darkroom.php b/src/Image/Darkroom.php index ce78717ee0..3142631c88 100644 --- a/src/Image/Darkroom.php +++ b/src/Image/Darkroom.php @@ -38,7 +38,7 @@ public function __construct( public static function factory(string $type, array $settings = []): object { if (isset(static::$types[$type]) === false) { - throw new Exception('Invalid Darkroom type'); + throw new Exception(message: 'Invalid Darkroom type'); } $class = static::$types[$type]; diff --git a/src/Image/Darkroom/ImageMagick.php b/src/Image/Darkroom/ImageMagick.php index 227e0e2014..c117bb00ad 100644 --- a/src/Image/Darkroom/ImageMagick.php +++ b/src/Image/Darkroom/ImageMagick.php @@ -137,7 +137,7 @@ public function process(string $file, array $options = []): array // log broken commands if ($return !== 0) { - throw new Exception('The imagemagick convert command could not be executed: ' . $command); + throw new Exception(message: 'The imagemagick convert command could not be executed: ' . $command); } return $options; diff --git a/src/Image/Image.php b/src/Image/Image.php index e14d967656..66e6081508 100644 --- a/src/Image/Image.php +++ b/src/Image/Image.php @@ -130,7 +130,9 @@ public function html(array $attr = []): string return Html::img($url, $attr); } - throw new LogicException('Calling Image::html() requires that the URL property is not null'); + throw new LogicException( + message: 'Calling Image::html() requires that the URL property is not null' + ); } /** diff --git a/src/Image/QrCode.php b/src/Image/QrCode.php index 3a3a06e0b6..5619ad7a34 100644 --- a/src/Image/QrCode.php +++ b/src/Image/QrCode.php @@ -193,7 +193,9 @@ public function write( 'png' => imagepng($this->toImage(...$args), $file), 'svg' => F::write($file, $this->toSvg(...$args)), 'webp' => imagewebp($this->toImage(...$args), $file), - default => throw new InvalidArgumentException('Cannot write QR code as ' . $format) + default => throw new InvalidArgumentException( + message: 'Cannot write QR code as ' . $format + ) }; } @@ -446,7 +448,7 @@ protected function encodeData(): array 0 => $this->encodeNumeric($data, $group), 1 => $this->encodeAlphanum($data, $group), 2 => $this->encodeBinary($data, $group), - default => throw new LogicException('Invalid QR mode') // @codeCoverageIgnore + default => throw new LogicException(message: 'Invalid QR mode') // @codeCoverageIgnore }; $code = [...$code, ...array_fill(0, 4, 0)]; @@ -836,7 +838,7 @@ protected function mask(int $mask, int $row, int $column): int 5 => !(((($row * $column) % 2) + (($row * $column) % 3))), 6 => !(((($row * $column) % 2) + (($row * $column) % 3)) % 2), 7 => !(((($row + $column) % 2) + (($row * $column) % 3)) % 2), - default => throw new LogicException('Invalid QR mask') // @codeCoverageIgnore + default => throw new LogicException(message: 'Invalid QR mask') // @codeCoverageIgnore }; } diff --git a/src/Option/OptionsApi.php b/src/Option/OptionsApi.php index a3b7ae8809..c4f96bf6f9 100644 --- a/src/Option/OptionsApi.php +++ b/src/Option/OptionsApi.php @@ -111,7 +111,9 @@ public function resolve(ModelWithContent $model, bool $safeMode = true): Options // @codeCoverageIgnoreStart if ($data === null) { - throw new NotFoundException('Options could not be loaded from API: ' . $model->toSafeString($this->url)); + throw new NotFoundException( + message: 'Options could not be loaded from API: ' . $model->toSafeString($this->url) + ); } // @codeCoverageIgnoreEnd diff --git a/src/Option/OptionsQuery.php b/src/Option/OptionsQuery.php index e1d8e4d4bc..7d570fecea 100644 --- a/src/Option/OptionsQuery.php +++ b/src/Option/OptionsQuery.php @@ -161,7 +161,9 @@ public function resolve(ModelWithContent $model, bool $safeMode = true): Options if ($result instanceof Collection === false) { $type = is_object($result) === true ? $result::class : gettype($result); - throw new InvalidArgumentException('Invalid query result data: ' . $type); + throw new InvalidArgumentException( + message: 'Invalid query result data: ' . $type + ); } // create options array diff --git a/src/Panel/Assets.php b/src/Panel/Assets.php index 1bf45a8669..6396c89aa2 100644 --- a/src/Panel/Assets.php +++ b/src/Panel/Assets.php @@ -189,7 +189,9 @@ public function favicons(): array ]; } - throw new InvalidArgumentException('Invalid panel.favicon option'); + throw new InvalidArgumentException( + message: 'Invalid panel.favicon option' + ); } /** @@ -291,7 +293,9 @@ public function link(): bool // copy assets to the dist folder if (Dir::copy($panelRoot, $versionRoot) !== true) { - throw new Exception('Panel assets could not be linked'); + throw new Exception( + message: 'Panel assets could not be linked' + ); } return true; diff --git a/src/Panel/Controller/Changes.php b/src/Panel/Controller/Changes.php index 5f581bd305..615dff0e8f 100644 --- a/src/Panel/Controller/Changes.php +++ b/src/Panel/Controller/Changes.php @@ -98,7 +98,7 @@ public static function save(ModelWithContent $model, array $input): array */ public static function unlock(ModelWithContent $model): array { - throw new Exception('Not yet implemented'); + throw new Exception(message: 'Not yet implemented'); return [ 'status' => 'ok' diff --git a/src/Panel/Home.php b/src/Panel/Home.php index 3abb1c460f..cac3ad230b 100644 --- a/src/Panel/Home.php +++ b/src/Panel/Home.php @@ -80,7 +80,9 @@ public static function alternative(User $user): string return Panel::url($menuItem['link']); } - throw new NotFoundException('There’s no available Panel page to redirect to'); + throw new NotFoundException( + message: 'There’s no available Panel page to redirect to' + ); } /** @@ -219,7 +221,9 @@ public static function url(): string // compare domains to avoid external redirects if (static::hasValidDomain($uri) !== true) { - throw new InvalidArgumentException('External URLs are not allowed for Panel redirects'); + throw new InvalidArgumentException( + message: 'External URLs are not allowed for Panel redirects' + ); } // remove all params to avoid diff --git a/src/Panel/Lab/Example.php b/src/Panel/Lab/Example.php index 37ad2b7778..d4d74e6195 100644 --- a/src/Panel/Lab/Example.php +++ b/src/Panel/Lab/Example.php @@ -34,7 +34,9 @@ public function __construct( $this->root = $this->parent->root() . '/' . $this->id; if ($this->exists() === false) { - throw new NotFoundException('The example could not be found'); + throw new NotFoundException( + message: 'The example could not be found' + ); } $this->tabs = $this->collectTabs(); diff --git a/src/Panel/PageCreateDialog.php b/src/Panel/PageCreateDialog.php index add72e34ba..e4a25d0cea 100644 --- a/src/Panel/PageCreateDialog.php +++ b/src/Panel/PageCreateDialog.php @@ -114,7 +114,9 @@ public function coreFields(): array $slug = $this->blueprint()->create()['slug'] ?? null; if ($title === false || $slug === false) { - throw new InvalidArgumentException('Page create dialog: title and slug must not be false'); + throw new InvalidArgumentException( + message: 'Page create dialog: title and slug must not be false' + ); } // title field @@ -158,15 +160,21 @@ public function customFields(): array foreach ($blueprint->create()['fields'] ?? [] as $name) { if (!$field = ($fields[$name] ?? null)) { - throw new InvalidArgumentException('Unknown field "' . $name . '" in create dialog'); + throw new InvalidArgumentException( + message: 'Unknown field "' . $name . '" in create dialog' + ); } if (in_array($field['type'], static::$fieldTypes, true) === false) { - throw new InvalidArgumentException('Field type "' . $field['type'] . '" not supported in create dialog'); + throw new InvalidArgumentException( + message: 'Field type "' . $field['type'] . '" not supported in create dialog' + ); } if (in_array($name, $ignore, true) === true) { - throw new InvalidArgumentException('Field name "' . $name . '" not allowed as custom field in create dialog'); + throw new InvalidArgumentException( + message: 'Field name "' . $name . '" not allowed as custom field in create dialog' + ); } // switch all fields to 1/1 diff --git a/src/Panel/Panel.php b/src/Panel/Panel.php index baf6d699fb..40c10b86d2 100644 --- a/src/Panel/Panel.php +++ b/src/Panel/Panel.php @@ -270,7 +270,9 @@ public static function response($result, array $options = []): Response // interpret missing/empty results as not found if ($result === null || $result === false) { - $result = new NotFoundException('The data could not be found'); + $result = new NotFoundException( + message: 'The data could not be found' + ); // interpret strings as errors } elseif (is_string($result) === true) { diff --git a/src/Panel/Ui/Component.php b/src/Panel/Ui/Component.php index 681b9c3b87..9cb23748e7 100644 --- a/src/Panel/Ui/Component.php +++ b/src/Panel/Ui/Component.php @@ -38,7 +38,9 @@ public function __construct( public function __call(string $name, array $args = []) { if (property_exists($this, $name) === false) { - throw new LogicException('The property "' . $name . '" does not exist on the UI component "' . $this->component . '"'); + throw new LogicException( + message: 'The property "' . $name . '" does not exist on the UI component "' . $this->component . '"' + ); } // getter diff --git a/src/Panel/Ui/FilePreview.php b/src/Panel/Ui/FilePreview.php index 6c1ee88a88..751a9eb1da 100644 --- a/src/Panel/Ui/FilePreview.php +++ b/src/Panel/Ui/FilePreview.php @@ -71,7 +71,9 @@ final public static function factory(File $file): static foreach ($handlers as $handler) { if (is_subclass_of($handler, self::class) === false) { - throw new InvalidArgumentException('File preview handler "' . $handler . '" must extend ' . self::class); + throw new InvalidArgumentException( + message: 'File preview handler "' . $handler . '" must extend ' . self::class + ); } if ($handler::accepts($file) === true) { diff --git a/src/Query/Expression.php b/src/Query/Expression.php index 170b65bc23..812fd18f79 100644 --- a/src/Query/Expression.php +++ b/src/Query/Expression.php @@ -101,7 +101,9 @@ public function resolve(array|object $data = []): mixed // if `a` isn't false, return `b`, otherwise `c` if ($part === '?') { if (($this->parts[$index + 2] ?? null) !== ':') { - throw new LogicException('Query: Incomplete ternary operator (missing matching `? :`)'); + throw new LogicException( + message: 'Query: Incomplete ternary operator (missing matching `? :`)' + ); } if ($base != false) { diff --git a/src/Query/Segment.php b/src/Query/Segment.php index e7c8ad9f9d..a4271552b4 100644 --- a/src/Query/Segment.php +++ b/src/Query/Segment.php @@ -145,7 +145,9 @@ protected function resolveArray(array $array, array $args): mixed array_key_exists($this->method, $array) && $args !== [] ) { - throw new InvalidArgumentException('Cannot access array element "' . $this->method . '" with arguments'); + throw new InvalidArgumentException( + message: 'Cannot access array element "' . $this->method . '" with arguments' + ); } // last, the standard error for trying to access something diff --git a/src/Sane/Sane.php b/src/Sane/Sane.php index 97de17e416..9d753ee1df 100644 --- a/src/Sane/Sane.php +++ b/src/Sane/Sane.php @@ -72,7 +72,9 @@ public static function handler( return null; } - throw new NotFoundException('Missing handler for type: "' . $type . '"'); + throw new NotFoundException( + message: 'Missing handler for type: "' . $type . '"' + ); } /** diff --git a/src/Sane/Svg.php b/src/Sane/Svg.php index dc2413b486..7d8d22d1fa 100644 --- a/src/Sane/Svg.php +++ b/src/Sane/Svg.php @@ -461,7 +461,7 @@ public static function validateDoctype( array $options ): void { if (mb_strtolower($doctype->name) !== 'svg') { - throw new InvalidArgumentException('Invalid doctype'); + throw new InvalidArgumentException(message: 'Invalid doctype'); } } @@ -495,7 +495,9 @@ protected static function parse(string $string): Dom // basic validation before we continue sanitizing/validating if ($root !== 'svg') { - throw new InvalidArgumentException('The file is not a SVG (got <' . $root . '>)'); + throw new InvalidArgumentException( + message: 'The file is not a SVG (got <' . $root . '>)' + ); } return $svg; diff --git a/src/Sane/Svgz.php b/src/Sane/Svgz.php index f59c31d9a2..e105d7b7ae 100644 --- a/src/Sane/Svgz.php +++ b/src/Sane/Svgz.php @@ -33,7 +33,7 @@ public static function sanitize( $string = @gzencode($string); if (is_string($string) !== true) { - throw new InvalidArgumentException('Could not recompress gzip data'); // @codeCoverageIgnore + throw new InvalidArgumentException(message: 'Could not recompress gzip data'); // @codeCoverageIgnore } return $string; @@ -66,7 +66,9 @@ protected static function uncompress(string $string): string $string = @gzdecode($string, 10000000); if (is_string($string) !== true) { - throw new InvalidArgumentException('Could not uncompress gzip data'); + throw new InvalidArgumentException( + message: 'Could not uncompress gzip data' + ); } return $string; diff --git a/src/Sane/Xml.php b/src/Sane/Xml.php index 797978d1d9..045babf37c 100644 --- a/src/Sane/Xml.php +++ b/src/Sane/Xml.php @@ -70,7 +70,9 @@ public static function validateDoctype( Str::contains($doctype->name, 'svg', true) === true ) ) { - throw new InvalidArgumentException('The doctype is not allowed in XML files'); + throw new InvalidArgumentException( + message: 'The doctype is not allowed in XML files' + ); } } } diff --git a/src/Template/Slot.php b/src/Template/Slot.php index be9f411bb5..e652886216 100644 --- a/src/Template/Slot.php +++ b/src/Template/Slot.php @@ -70,7 +70,7 @@ public static function begin(string $name = 'default'): static|null public function close(): void { if ($this->open === false) { - throw new LogicException('The slot has not been opened'); + throw new LogicException(message: 'The slot has not been opened'); } $this->content = ob_get_clean(); diff --git a/src/Template/Snippet.php b/src/Template/Snippet.php index 42a3f4a05a..f6ffa04d65 100644 --- a/src/Template/Snippet.php +++ b/src/Template/Snippet.php @@ -101,7 +101,9 @@ public function close(): static // is only supported if the snippet has // been started before if ($this->open === false) { - throw new LogicException('The snippet has not been opened'); + throw new LogicException( + message: 'The snippet has not been opened' + ); } // create a default slot for the content @@ -296,7 +298,9 @@ protected static function scope( array_key_exists('slot', $data) === true || array_key_exists('slots', $data) === true ) { - throw new InvalidArgumentException('Passing the $slot or $slots variables to snippets is not supported.'); + throw new InvalidArgumentException( + message: 'Passing the $slot or $slots variables to snippets is not supported.' + ); } return [ diff --git a/src/Text/KirbyTag.php b/src/Text/KirbyTag.php index 83ac984a46..bfc4775407 100644 --- a/src/Text/KirbyTag.php +++ b/src/Text/KirbyTag.php @@ -46,7 +46,9 @@ public function __construct( // type aliases if (isset(static::$types[$type]) === false) { if (isset(static::$aliases[$type]) === false) { - throw new InvalidArgumentException('Undefined tag type: ' . $type); + throw new InvalidArgumentException( + message: 'Undefined tag type: ' . $type + ); } $type = static::$aliases[$type]; @@ -230,7 +232,9 @@ public function render(): string return (string)$callback($this); } - throw new BadMethodCallException('Invalid tag render function in tag: ' . $this->type); + throw new BadMethodCallException( + message: 'Invalid tag render function in tag: ' . $this->type + ); } public function type(): string diff --git a/src/Toolkit/A.php b/src/Toolkit/A.php index 7e3cfc2143..b69c071d87 100644 --- a/src/Toolkit/A.php +++ b/src/Toolkit/A.php @@ -433,7 +433,9 @@ public static function keyBy(array $array, string|callable $keyBy): array static::pluck($array, $keyBy); if (count($keys) !== count($array)) { - throw new InvalidArgumentException('The "key by" argument must be a valid key or a callable'); + throw new InvalidArgumentException( + message: 'The "key by" argument must be a valid key or a callable' + ); } return array_combine($keys, $array); @@ -641,11 +643,11 @@ public static function move(array $array, int $from, int $to): array $total = count($array); if ($from >= $total || $from < 0) { - throw new Exception('Invalid "from" index'); + throw new Exception(message: 'Invalid "from" index'); } if ($to >= $total || $to < 0) { - throw new Exception('Invalid "to" index'); + throw new Exception(message: 'Invalid "to" index'); } // remove the item from the array @@ -747,7 +749,9 @@ public static function random( bool $shuffle = false ): array { if ($count > count($array)) { - throw new InvalidArgumentException('$count is larger than available array items'); + throw new InvalidArgumentException( + message: '$count is larger than available array items' + ); } if ($shuffle === true) { diff --git a/src/Toolkit/Collection.php b/src/Toolkit/Collection.php index 8636fd5226..4add106968 100644 --- a/src/Toolkit/Collection.php +++ b/src/Toolkit/Collection.php @@ -522,17 +522,23 @@ public function group( // make sure that there's always a proper value to group by if (!$value) { - throw new Exception('Invalid grouping value for key: ' . $key); + throw new Exception( + message: 'Invalid grouping value for key: ' . $key + ); } // make sure we have a proper key for each group if (is_array($value) === true) { - throw new Exception('You cannot group by arrays or objects'); + throw new Exception( + message: 'You cannot group by arrays or objects' + ); } if (is_object($value) === true) { if (method_exists($value, '__toString') === false) { - throw new Exception('You cannot group by arrays or objects'); + throw new Exception( + message: 'You cannot group by arrays or objects' + ); } $value = (string)$value; @@ -550,7 +556,9 @@ public function group( return new self($groups); } - throw new Exception('Can only group by string values or by providing a callback function'); + throw new Exception( + message: 'Can only group by string values or by providing a callback function' + ); } /** diff --git a/src/Toolkit/Component.php b/src/Toolkit/Component.php index d3a865cbbd..ba274f58df 100644 --- a/src/Toolkit/Component.php +++ b/src/Toolkit/Component.php @@ -67,7 +67,9 @@ public function __construct( protected array $attrs = [] ) { if (isset(static::$types[$type]) === false) { - throw new InvalidArgumentException('Undefined component type: ' . $type); + throw new InvalidArgumentException( + message: 'Undefined component type: ' . $type + ); } $this->options = $options = static::setup($type); diff --git a/src/Toolkit/Date.php b/src/Toolkit/Date.php index 9d9253ddde..c719b81bd7 100644 --- a/src/Toolkit/Date.php +++ b/src/Toolkit/Date.php @@ -379,7 +379,9 @@ public function round(string $unit, int $size = 1): static $unit === 'hour' && 24 % $size !== 0 || in_array($unit, ['second', 'minute'], true) && 60 % $size !== 0 ) { - throw new InvalidArgumentException('Invalid rounding size for ' . $unit); + throw new InvalidArgumentException( + message: 'Invalid rounding size for ' . $unit + ); } // round to other rounding steps @@ -475,7 +477,7 @@ public static function stepConfig( return [...$default, 'unit' => strtolower($input)]; } - throw new InvalidArgumentException('Invalid input'); + throw new InvalidArgumentException(message: 'Invalid input'); } /** @@ -527,7 +529,9 @@ public function toString( 'date' => 'Y-m-d', 'time' => 'H:i:s', 'datetime' => 'Y-m-d H:i:s', - default => throw new InvalidArgumentException('Invalid mode') + default => throw new InvalidArgumentException( + message: 'Invalid mode' + ) }; if ($timezone === true) { @@ -559,7 +563,9 @@ protected static function validateUnit(string $unit): void { $units = ['year', 'month', 'day', 'hour', 'minute', 'second']; if (in_array($unit, $units, true) === false) { - throw new InvalidArgumentException('Invalid rounding unit'); + throw new InvalidArgumentException( + message: 'Invalid rounding unit' + ); } } } diff --git a/src/Toolkit/Dom.php b/src/Toolkit/Dom.php index 227ce2b525..2e19c026cb 100644 --- a/src/Toolkit/Dom.php +++ b/src/Toolkit/Dom.php @@ -922,11 +922,15 @@ protected function validateDoctype( empty($doctype->publicId) === false || empty($doctype->systemId) === false ) { - throw new InvalidArgumentException('The doctype must not reference external files'); + throw new InvalidArgumentException( + message: 'The doctype must not reference external files' + ); } if (empty($doctype->internalSubset) === false) { - throw new InvalidArgumentException('The doctype must not define a subset'); + throw new InvalidArgumentException( + message: 'The doctype must not define a subset' + ); } if ($options['doctypeCallback']) { diff --git a/src/Toolkit/Obj.php b/src/Toolkit/Obj.php index b5b6712f09..7718f95f90 100644 --- a/src/Toolkit/Obj.php +++ b/src/Toolkit/Obj.php @@ -61,7 +61,9 @@ public function get(string|array $property, $fallback = null) $fallback ??= []; if (is_array($fallback) === false) { - throw new InvalidArgumentException('The fallback value must be an array when getting multiple properties'); + throw new InvalidArgumentException( + message: 'The fallback value must be an array when getting multiple properties' + ); } $result = []; diff --git a/src/Toolkit/Str.php b/src/Toolkit/Str.php index 85ac7aeeab..54573e088b 100644 --- a/src/Toolkit/Str.php +++ b/src/Toolkit/Str.php @@ -723,7 +723,9 @@ public static function position( bool $caseInsensitive = false ): int|false { if ($needle === '') { - throw new InvalidArgumentException('The needle must not be empty'); + throw new InvalidArgumentException( + message: 'The needle must not be empty' + ); } if ($caseInsensitive === true) { @@ -889,7 +891,9 @@ public static function replacements( return [compact('search', 'replace', 'limit')]; } - throw new InvalidArgumentException('Invalid combination of $search, $replace and $limit params.'); + throw new InvalidArgumentException( + message: 'Invalid combination of $search, $replace and $limit params.' + ); } /** @@ -908,7 +912,9 @@ public static function replaceReplacements( // behavior is identical to the official PHP str_replace() foreach ($replacements as $replacement) { if (is_int($replacement['limit']) === false) { - throw new Exception('Invalid limit "' . $replacement['limit'] . '".'); + throw new Exception( + message: 'Invalid limit "' . $replacement['limit'] . '".' + ); } if ($replacement['limit'] === -1) { diff --git a/src/Toolkit/SymmetricCrypto.php b/src/Toolkit/SymmetricCrypto.php index 7020e83365..ee7f8fc4c9 100644 --- a/src/Toolkit/SymmetricCrypto.php +++ b/src/Toolkit/SymmetricCrypto.php @@ -40,11 +40,15 @@ public function __construct( protected string|null $secretKey = null, ) { if ($password !== null && $secretKey !== null) { - throw new InvalidArgumentException('Passing both a secret key and a password is not supported'); + throw new InvalidArgumentException( + message: 'Passing both a secret key and a password is not supported' + ); } if ($secretKey !== null && strlen($secretKey) !== SODIUM_CRYPTO_SECRETBOX_KEYBYTES) { - throw new InvalidArgumentException('Invalid secret key length, expected ' . SODIUM_CRYPTO_SECRETBOX_KEYBYTES . ' bytes'); + throw new InvalidArgumentException( + message: 'Invalid secret key length, expected ' . SODIUM_CRYPTO_SECRETBOX_KEYBYTES . ' bytes' + ); } } @@ -91,7 +95,9 @@ public function decrypt(string $json): string $props = Json::decode($json); if (($props['mode'] ?? null) !== 'secretbox') { - throw new InvalidArgumentException('Unsupported encryption mode "' . ($props['mode'] ?? '') . '"'); + throw new InvalidArgumentException( + message: 'Unsupported encryption mode "' . ($props['mode'] ?? '') . '"' + ); } if ( @@ -100,7 +106,9 @@ public function decrypt(string $json): string isset($props['salt']) !== true || isset($props['limits']) !== true ) { - throw new InvalidArgumentException('Input data does not contain all required props'); + throw new InvalidArgumentException( + message: 'Input data does not contain all required props' + ); } $data = base64_decode($props['data']); @@ -111,7 +119,9 @@ public function decrypt(string $json): string $plaintext = sodium_crypto_secretbox_open($data, $nonce, $this->secretKey($salt, $limits)); if (is_string($plaintext) !== true) { - throw new LogicException('Encrypted string was tampered with'); + throw new LogicException( + message: 'Encrypted string was tampered with' + ); } return $plaintext; @@ -180,7 +190,9 @@ public function secretKey( // derive from password if (isset($this->password) === true) { if ($salt === null || $limits === null) { - throw new InvalidArgumentException('Salt and limits are required when deriving a secret key from a password'); + throw new InvalidArgumentException( + message: 'Salt and limits are required when deriving a secret key from a password' + ); } // access from cache diff --git a/src/Toolkit/Totp.php b/src/Toolkit/Totp.php index c57febf248..fd56be8af7 100644 --- a/src/Toolkit/Totp.php +++ b/src/Toolkit/Totp.php @@ -50,7 +50,9 @@ public function __construct( // safety check to avoid accidental insecure secrets if ($force === false && strlen($this->secret) !== 20) { - throw new InvalidArgumentException('TOTP secrets should be 32 Base32 digits (= 20 bytes)'); + throw new InvalidArgumentException( + message: 'TOTP secrets should be 32 Base32 digits (= 20 bytes)' + ); } } diff --git a/src/Toolkit/V.php b/src/Toolkit/V.php index 0727e1980b..b51c929e6a 100644 --- a/src/Toolkit/V.php +++ b/src/Toolkit/V.php @@ -347,7 +347,9 @@ public static function __callStatic(string $method, array $arguments): bool '>=' => $value >= $test, '==' => $value === $test, - default => throw new InvalidArgumentException('Invalid date comparison operator: "' . $operator . '". Allowed operators: "==", "!=", "<", "<=", ">", ">="') + default => throw new InvalidArgumentException( + message: 'Invalid date comparison operator: "' . $operator . '". Allowed operators: "==", "!=", "<", "<=", ">", ">="' + ) }; }, diff --git a/src/Uuid/Uuid.php b/src/Uuid/Uuid.php index e52522fe41..bb8577d0a2 100644 --- a/src/Uuid/Uuid.php +++ b/src/Uuid/Uuid.php @@ -68,7 +68,9 @@ public function __construct( ) { // throw exception when globally disabled if (Uuids::enabled() === false) { - throw new LogicException('UUIDs have been disabled via the `content.uuid` config option.'); + throw new LogicException( + message: 'UUIDs have been disabled via the `content.uuid` config option.' + ); } @@ -84,7 +86,9 @@ public function __construct( // in the rare case that both model and ID string // got passed, make sure they match if ($uuid && $uuid !== $this->uri->toString()) { - throw new LogicException('UUID: can\'t create new instance from both model and UUID string that do not match'); + throw new LogicException( + message: 'UUID: can\'t create new instance from both model and UUID string that do not match' + ); } } elseif ($uuid) { $this->uri = new Uri($uuid); @@ -134,7 +138,9 @@ final public function context(): Generator */ protected function findByCache(): Identifiable|null { - throw new LogicException('UUID class needs to implement the ::findByCache() method'); + throw new LogicException( + message: 'UUID class needs to implement the ::findByCache() method' + ); } /** @@ -146,7 +152,9 @@ protected function findByCache(): Identifiable|null */ protected function findByIndex(): Identifiable|null { - throw new LogicException('UUID class needs to implement the ::findByIndex() method'); + throw new LogicException( + message: 'UUID class needs to implement the ::findByIndex() method' + ); } /** @@ -173,7 +181,9 @@ final public static function for( // TODO: activate for uuid-block-structure-support // 'block' => new BlockUuid(uuid: $seed, context: $context), // 'struct' => new StructureUuid(uuid: $seed, context: $context), - default => throw new InvalidArgumentException('Invalid UUID URI: ' . $seed) + default => throw new InvalidArgumentException( + message: 'Invalid UUID URI: ' . $seed + ) }; } @@ -187,7 +197,9 @@ final public static function for( ); } - throw new InvalidArgumentException('Invalid UUID string: ' . $seed); + throw new InvalidArgumentException( + message: 'Invalid UUID string: ' . $seed + ); } // for model object @@ -205,8 +217,9 @@ final public static function for( // => new BlockUuid(model: $seed, context: $context), // $seed instanceof StructureObject // => new StructureUuid(model: $seed, context: $context), - default - => throw new InvalidArgumentException('UUID not supported for: ' . $seed::class) + default => throw new InvalidArgumentException( + message: 'UUID not supported for: ' . $seed::class + ) }; } @@ -341,7 +354,9 @@ public function model(bool $lazy = false): Identifiable|null if ($lazy === false) { if (App::instance()->option('content.uuid.index') === false) { - throw new NotFoundException('Model for UUID ' . $this->uri->toString() . ' could not be found without searching in the site index'); + throw new NotFoundException( + message: 'Model for UUID ' . $this->uri->toString() . ' could not be found without searching in the site index' + ); } if ($this->model = $this->findByIndex()) { diff --git a/src/Uuid/Uuids.php b/src/Uuid/Uuids.php index c6bc911dba..4e7176eefe 100644 --- a/src/Uuid/Uuids.php +++ b/src/Uuid/Uuids.php @@ -93,7 +93,9 @@ public static function enabled(): bool public static function generate(string $type = 'all'): void { if (static::enabled() === false) { - throw new LogicException('UUIDs have been disabled via the `content.uuid` config option.'); + throw new LogicException( + message: 'UUIDs have been disabled via the `content.uuid` config option.' + ); } static::each( @@ -111,7 +113,9 @@ public static function generate(string $type = 'all'): void public static function populate(string $type = 'all'): void { if (static::enabled() === false) { - throw new LogicException('UUIDs have been disabled via the `content.uuid` config option.'); + throw new LogicException( + message: 'UUIDs have been disabled via the `content.uuid` config option.' + ); } static::each( diff --git a/tests/Cms/Api/ApiTest.php b/tests/Cms/Api/ApiTest.php index 53de1c2238..24fb274895 100644 --- a/tests/Cms/Api/ApiTest.php +++ b/tests/Cms/Api/ApiTest.php @@ -2,6 +2,7 @@ namespace Kirby\Cms; +use Exception; use Kirby\Exception\AuthException; use Kirby\Exception\InvalidArgumentException; use Kirby\Exception\NotFoundException; @@ -630,7 +631,7 @@ public function testRenderExceptionWithDebugging() 'pattern' => 'test', 'method' => 'POST', 'action' => function () { - throw new \Exception('nope'); + throw new Exception('nope'); } ] ] diff --git a/tests/Cms/App/AppIoTest.php b/tests/Cms/App/AppIoTest.php index b458389b9d..419a2b7ed0 100644 --- a/tests/Cms/App/AppIoTest.php +++ b/tests/Cms/App/AppIoTest.php @@ -44,7 +44,7 @@ public function testExceptionErrorPage() ] ]); - $response = $app->io(new Exception('Nope')); + $response = $app->io(new Exception(message: 'Nope')); $this->assertSame(500, $response->code()); $this->assertSame('Error: Nope', $response->body()); diff --git a/tests/Cms/Helpers/HelpersTest.php b/tests/Cms/Helpers/HelpersTest.php index f0d8749c70..d452196a2e 100644 --- a/tests/Cms/Helpers/HelpersTest.php +++ b/tests/Cms/Helpers/HelpersTest.php @@ -135,8 +135,12 @@ public function testHandleErrorsException() $this->expectExceptionMessage('Exception inside the action'); Helpers::handleErrors( - fn () => throw new Exception('Exception inside the action'), - fn () => $this->fail('Condition handler should not be called because no warning was triggered') + fn () => throw new Exception( + message: 'Exception inside the action' + ), + fn () => $this->fail( + 'Condition handler should not be called because no warning was triggered' + ) ); } diff --git a/tests/Cms/Pages/PageActionsTest.php b/tests/Cms/Pages/PageActionsTest.php index 400872d73f..fadf51877a 100644 --- a/tests/Cms/Pages/PageActionsTest.php +++ b/tests/Cms/Pages/PageActionsTest.php @@ -2,6 +2,7 @@ namespace Kirby\Cms; +use Exception; use Kirby\Content\ContentTranslation; use Kirby\Content\VersionId; use Kirby\Filesystem\Dir; @@ -106,7 +107,7 @@ public function testChangeNumWhenNumStaysTheSame() ], 'hooks' => [ 'page.changeNum:before' => function () { - throw new \Exception('This should not be called'); + throw new Exception('This should not be called'); } ] ]); diff --git a/tests/Exception/ExceptionTest.php b/tests/Exception/ExceptionTest.php index 933837b948..c58ff729e8 100644 --- a/tests/Exception/ExceptionTest.php +++ b/tests/Exception/ExceptionTest.php @@ -117,7 +117,7 @@ public function testJustMessage() */ public function testJustMessageWithNamedArgument() { - $exception = new Exception('Another error occurred'); + $exception = new Exception(message: 'Another error occurred'); $this->assertSame('error.general', $exception->getKey()); $this->assertSame('Another error occurred', $exception->getMessage()); @@ -131,7 +131,7 @@ public function testJustMessageWithNamedArgument() */ public function testPrevious() { - $previous = new Exception('Previous'); + $previous = new Exception(message: 'Previous'); $exception = new Exception(previous: $previous); $this->assertNull($previous->getPrevious()); @@ -143,7 +143,7 @@ public function testPrevious() */ public function testPreviousWithNamedArgument() { - $previous = new Exception('Previous'); + $previous = new Exception(message: 'Previous'); $exception = new Exception(previous: $previous); $this->assertNull($previous->getPrevious()); diff --git a/tests/Form/FieldClassTest.php b/tests/Form/FieldClassTest.php index f8b0eba4dc..c83ae4fff1 100644 --- a/tests/Form/FieldClassTest.php +++ b/tests/Form/FieldClassTest.php @@ -2,6 +2,7 @@ namespace Kirby\Form; +use Exception; use Kirby\Cms\Page; use Kirby\Exception\InvalidArgumentException; use Kirby\TestCase; @@ -50,7 +51,7 @@ public function validations(): array 'minlength', 'custom' => function ($value) { if ($value !== 'a') { - throw new \Exception('Please enter an a'); + throw new Exception('Please enter an a'); } } ]; diff --git a/tests/Form/FieldTest.php b/tests/Form/FieldTest.php index e041fc9450..fbeddc2348 100644 --- a/tests/Form/FieldTest.php +++ b/tests/Form/FieldTest.php @@ -951,7 +951,9 @@ public function testCustomValidations() 'test' => [ 'validations' => [ 'test' => function ($value) { - throw new InvalidArgumentException('Invalid value: ' . $value); + throw new InvalidArgumentException( + message: 'Invalid value: ' . $value + ); } ] ] diff --git a/tests/Http/Exceptions/NextRouteExceptionTest.php b/tests/Http/Exceptions/NextRouteExceptionTest.php index 79ba230950..3bbbc60065 100644 --- a/tests/Http/Exceptions/NextRouteExceptionTest.php +++ b/tests/Http/Exceptions/NextRouteExceptionTest.php @@ -2,6 +2,7 @@ namespace Kirby\Http\Exceptions; +use Exception; use Kirby\TestCase; class NextRouteExceptionTest extends TestCase @@ -11,8 +12,8 @@ class NextRouteExceptionTest extends TestCase */ public function testException() { - $exception = new NextRouteException('test'); - $this->assertInstanceOf(\Exception::class, $exception); + $exception = new NextRouteException(message: 'test'); + $this->assertInstanceOf(Exception::class, $exception); $this->assertSame('test', $exception->getMessage()); } } diff --git a/tests/Panel/DialogTest.php b/tests/Panel/DialogTest.php index e04b97ff20..e8ab599fa0 100644 --- a/tests/Panel/DialogTest.php +++ b/tests/Panel/DialogTest.php @@ -2,7 +2,9 @@ namespace Kirby\Panel; +use Exception; use Kirby\Cms\App; +use Kirby\Exception\NotFoundException; use Kirby\Filesystem\Dir; use Kirby\TestCase; @@ -122,7 +124,7 @@ public function testResponseFromInvalidData(): void */ public function testResponseFromException(): void { - $exception = new \Exception('Test'); + $exception = new Exception('Test'); $response = Dialog::response($exception); $expected = [ '$dialog' => [ @@ -142,7 +144,7 @@ public function testResponseFromException(): void */ public function testResponseFromKirbyException(): void { - $exception = new \Kirby\Exception\NotFoundException('Test'); + $exception = new NotFoundException(message: 'Test'); $response = Dialog::response($exception); $expected = [ '$dialog' => [ diff --git a/tests/Panel/DropdownTest.php b/tests/Panel/DropdownTest.php index a4655ed242..5b3c1e9312 100644 --- a/tests/Panel/DropdownTest.php +++ b/tests/Panel/DropdownTest.php @@ -2,7 +2,9 @@ namespace Kirby\Panel; +use Exception; use Kirby\Cms\App; +use Kirby\Exception\NotFoundException; use Kirby\Filesystem\Dir; use Kirby\TestCase; @@ -104,7 +106,7 @@ public function testResponseFromInvalidData(): void */ public function testResponseFromException(): void { - $exception = new \Exception('Test'); + $exception = new Exception('Test'); $response = Dropdown::response($exception); $expected = [ '$dropdown' => [ @@ -124,7 +126,7 @@ public function testResponseFromException(): void */ public function testResponseFromKirbyException(): void { - $exception = new \Kirby\Exception\NotFoundException('Test'); + $exception = new NotFoundException(message: 'Test'); $response = Dropdown::response($exception); $expected = [ '$dropdown' => [ diff --git a/tests/Panel/ViewTest.php b/tests/Panel/ViewTest.php index cd42c22297..4365eeb84b 100644 --- a/tests/Panel/ViewTest.php +++ b/tests/Panel/ViewTest.php @@ -4,6 +4,7 @@ use Kirby\Cms\App; use Kirby\Cms\Language; +use Kirby\Exception\NotFoundException; use Kirby\Filesystem\Dir; use Kirby\Http\Response; use Kirby\TestCase; @@ -609,7 +610,7 @@ public function testResponseFromKirbyException() ] ]); - $exception = new \Kirby\Exception\NotFoundException('Test'); + $exception = new NotFoundException(message: 'Test'); $response = View::response($exception); $json = json_decode($response->body(), true); diff --git a/tests/Text/KirbyTagsTest.php b/tests/Text/KirbyTagsTest.php index b48a75a4d4..efd4e1177d 100644 --- a/tests/Text/KirbyTagsTest.php +++ b/tests/Text/KirbyTagsTest.php @@ -107,10 +107,14 @@ public function testParseWithException() 'html' => fn () => throw new Exception('Just for fun') ], 'invalidargument' => [ - 'html' => fn () => throw new InvalidArgumentException('Just for fun') + 'html' => fn () => throw new InvalidArgumentException( + message: 'Just for fun' + ) ], 'undefined' => [ - 'html' => fn () => throw new InvalidArgumentException('Undefined tag type: undefined') + 'html' => fn () => throw new InvalidArgumentException( + message: 'Undefined tag type: undefined' + ) ] ]; @@ -160,7 +164,9 @@ public function testParseWithExceptionDebug3() { KirbyTag::$types = [ 'undefined' => [ - 'html' => fn () => throw new InvalidArgumentException('Undefined tag type: undefined') + 'html' => fn () => throw new InvalidArgumentException( + message: 'Undefined tag type: undefined' + ) ] ]; diff --git a/tests/Toolkit/DomTest.php b/tests/Toolkit/DomTest.php index 97e72b7e67..535baa555a 100644 --- a/tests/Toolkit/DomTest.php +++ b/tests/Toolkit/DomTest.php @@ -8,9 +8,9 @@ use DOMDocumentType; use DOMElement; use Exception; -use Kirby\AssertionFailedError; use Kirby\Cms\App; use Kirby\Exception\InvalidArgumentException; +use PHPUnit\Framework\AssertionFailedError; /** * @coversDefaultClass \Kirby\Toolkit\Dom @@ -40,7 +40,11 @@ public static function setUpBeforeClass(): void if ($attr->nodeName === 'b') { $attr->ownerElement->removeAttributeNode($attr); - return [new InvalidArgumentException('The "b" attribute is not allowed')]; + return [ + new InvalidArgumentException( + message: 'The "b" attribute is not allowed' + ) + ]; } return []; @@ -50,7 +54,9 @@ public static function setUpBeforeClass(): void throw new AssertionFailedError('Options provided to callback are not complete or invalid'); } - throw new InvalidArgumentException('The "' . $doctype->name . '" doctype is not allowed'); + throw new InvalidArgumentException( + message: 'The "' . $doctype->name . '" doctype is not allowed' + ); }, 'sanitize_elementCallback1' => function (DOMElement $element, array $options): void { // no return value @@ -62,7 +68,11 @@ public static function setUpBeforeClass(): void if ($element->nodeName === 'b') { Dom::remove($element); - return [new InvalidArgumentException('The "b" element is not allowed')]; + return [ + new InvalidArgumentException( + message: 'The "b" element is not allowed' + ) + ]; } return []; @@ -1870,7 +1880,9 @@ public function testSanitizeDoctypeCallbackException() $dom = new Dom('', 'XML'); $dom->sanitize([ 'doctypeCallback' => function (DOMDocumentType $doctype): void { - throw new \InvalidArgumentException('This exception is not caught as validation error'); + throw new \InvalidArgumentException( + message: 'This exception is not caught as validation error' + ); } ]); }