Skip to content

Commit

Permalink
Type hinting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
acabal committed Jan 9, 2024
1 parent 716fc8b commit f9c8730
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions config/phpstan/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ parameters:
# Ignore errors caused by no type hints on class properties, as that's not available till PHP 7.4
- '#Property .+? has no type specified.#'

# Ignore errors caused by type hints that should be union types. Union types are not yet supported in PHP.
- '#Function vd(s|d)?\(\) has parameter \$var with no type specified.#'
# Ignore setters for properties that accept several types
- '#Property Artwork::\$Tags \(array<ArtworkTag>\) does not accept.+#'
level:
8
paths:
Expand Down
9 changes: 6 additions & 3 deletions lib/Artwork.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @property User $Submitter
* @property User $Reviewer
* @property ?ImageMimeType $MimeType
* @property array<ArtworkTag> $_Tags
* @property ?array<ArtworkTag> $_Tags
*/
class Artwork extends PropertiesBase{
public ?string $Name = null;
Expand Down Expand Up @@ -60,6 +60,9 @@ class Artwork extends PropertiesBase{
// SETTERS
// *******

/**
* @param string|null|array<ArtworkTag> $tags
*/
protected function SetTags(string|array|null $tags): void{
if($tags === null || is_array($tags)){
$this->_Tags = $tags;
Expand Down Expand Up @@ -289,14 +292,14 @@ protected function Validate(array &$uploadedFile = []): void{
$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.
if($this->Status !== COVER_ARTWORK_STATUS_IN_USE){
$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());
}

Expand Down
6 changes: 3 additions & 3 deletions lib/CoreFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
use function Safe\ob_start;

// Convenience alias of var_dump.
function vd($var): void{
function vd(mixed $var): void{
var_dump($var);
}

// var_dump($var) then die().
function vdd($var): void{
function vdd(mixed $var): void{
var_dump($var);
die();
}

// var_dump into a string.
function vds($var): string{
function vds(mixed $var): string{
ob_start();
var_dump($var);
$str = ob_get_contents();
Expand Down
2 changes: 1 addition & 1 deletion www/artworks/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
$artwork->Name = HttpInput::Str(POST, 'artwork-name', false);
$artwork->CompletedYear = HttpInput::Int(POST, 'artwork-year');
$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->EbookWwwFilesystemPath = HttpInput::Str(POST, 'artwork-ebook-www-filesystem-path', false);
$artwork->SubmitterUserId = $GLOBALS['User']->UserId ?? null;
Expand Down

0 comments on commit f9c8730

Please sign in to comment.