Type hinting fixes

This commit is contained in:
Alex Cabal 2024-01-09 12:06:28 -06:00
parent 716fc8bea9
commit f9c873003e
4 changed files with 12 additions and 9 deletions

View file

@ -11,8 +11,8 @@ parameters:
# Ignore errors caused by no type hints on class properties, as that's not available till PHP 7.4 # Ignore errors caused by no type hints on class properties, as that's not available till PHP 7.4
- '#Property .+? has no type specified.#' - '#Property .+? has no type specified.#'
# Ignore errors caused by type hints that should be union types. Union types are not yet supported in PHP. # Ignore setters for properties that accept several types
- '#Function vd(s|d)?\(\) has parameter \$var with no type specified.#' - '#Property Artwork::\$Tags \(array<ArtworkTag>\) does not accept.+#'
level: level:
8 8
paths: paths:

View file

@ -21,7 +21,7 @@ use function Safe\preg_replace;
* @property User $Submitter * @property User $Submitter
* @property User $Reviewer * @property User $Reviewer
* @property ?ImageMimeType $MimeType * @property ?ImageMimeType $MimeType
* @property array<ArtworkTag> $_Tags * @property ?array<ArtworkTag> $_Tags
*/ */
class Artwork extends PropertiesBase{ class Artwork extends PropertiesBase{
public ?string $Name = null; public ?string $Name = null;
@ -60,6 +60,9 @@ class Artwork extends PropertiesBase{
// SETTERS // SETTERS
// ******* // *******
/**
* @param string|null|array<ArtworkTag> $tags
*/
protected function SetTags(string|array|null $tags): void{ protected function SetTags(string|array|null $tags): void{
if($tags === null || is_array($tags)){ if($tags === null || is_array($tags)){
$this->_Tags = $tags; $this->_Tags = $tags;
@ -289,14 +292,14 @@ class Artwork extends PropertiesBase{
$error->Add(new Exceptions\MissingEbookException()); $error->Add(new Exceptions\MissingEbookException());
} }
if($this->Tags === null || count($this->_Tags) == 0){ if(count($this->Tags) == 0){
// In-use artwork doesn't have user-provided tags. // In-use artwork doesn't have user-provided tags.
if($this->Status !== COVER_ARTWORK_STATUS_IN_USE){ if($this->Status !== COVER_ARTWORK_STATUS_IN_USE){
$error->Add(new Exceptions\TagsRequiredException()); $error->Add(new Exceptions\TagsRequiredException());
} }
} }
if($this->Tags !== null && count($this->_Tags) > COVER_ARTWORK_MAX_TAGS){ if(count($this->Tags) > COVER_ARTWORK_MAX_TAGS){
$error->Add(new Exceptions\TooManyTagsException()); $error->Add(new Exceptions\TooManyTagsException());
} }

View file

@ -6,18 +6,18 @@ use function Safe\ob_end_clean;
use function Safe\ob_start; use function Safe\ob_start;
// Convenience alias of var_dump. // Convenience alias of var_dump.
function vd($var): void{ function vd(mixed $var): void{
var_dump($var); var_dump($var);
} }
// var_dump($var) then die(). // var_dump($var) then die().
function vdd($var): void{ function vdd(mixed $var): void{
var_dump($var); var_dump($var);
die(); die();
} }
// var_dump into a string. // var_dump into a string.
function vds($var): string{ function vds(mixed $var): string{
ob_start(); ob_start();
var_dump($var); var_dump($var);
$str = ob_get_contents(); $str = ob_get_contents();

View file

@ -30,7 +30,7 @@ try{
$artwork->Name = HttpInput::Str(POST, 'artwork-name', false); $artwork->Name = HttpInput::Str(POST, 'artwork-name', false);
$artwork->CompletedYear = HttpInput::Int(POST, 'artwork-year'); $artwork->CompletedYear = HttpInput::Int(POST, 'artwork-year');
$artwork->CompletedYearIsCirca = HttpInput::Bool(POST, 'artwork-year-is-circa', false); $artwork->CompletedYearIsCirca = HttpInput::Bool(POST, 'artwork-year-is-circa', false);
$artwork->Tags = HttpInput::Str(POST, 'artwork-tags', false); $artwork->Tags = HttpInput::Str(POST, 'artwork-tags', false) ?? [];
$artwork->Status = HttpInput::Str(POST, 'artwork-status', false, COVER_ARTWORK_STATUS_UNVERIFIED); $artwork->Status = HttpInput::Str(POST, 'artwork-status', false, COVER_ARTWORK_STATUS_UNVERIFIED);
$artwork->EbookWwwFilesystemPath = HttpInput::Str(POST, 'artwork-ebook-www-filesystem-path', false); $artwork->EbookWwwFilesystemPath = HttpInput::Str(POST, 'artwork-ebook-www-filesystem-path', false);
$artwork->SubmitterUserId = $GLOBALS['User']->UserId ?? null; $artwork->SubmitterUserId = $GLOBALS['User']->UserId ?? null;