diff --git a/src/app/Traits/EmailPropertyTrait.php b/src/app/Traits/EmailPropertyTrait.php index 08f93da9..01786a41 100644 --- a/src/app/Traits/EmailPropertyTrait.php +++ b/src/app/Traits/EmailPropertyTrait.php @@ -1,94 +1,94 @@ email) && defined('static::EMAIL_TEMPLATE')) { $template = static::EMAIL_TEMPLATE; // @phpstan-ignore-line $defaults = [ 'type' => 'mail', ]; foreach (['id', 'domainName', 'type'] as $prop) { if (strpos($template, "{{$prop}}") === false) { continue; } $value = $model->{$prop} ?? ($defaults[$prop] ?? ''); - if ($value === '' || $value === null) { + if ($value === '') { throw new \Exception("Missing '{$prop}' property for " . static::class); } $template = str_replace("{{$prop}}", $value, $template); } $model->email = strtolower($template); } }); } /** * Returns the object's domain (including soft-deleted). * * @return ?\App\Domain The domain to which the object belongs to, NULL if it does not exist */ public function domain(): ?\App\Domain { if (empty($this->email) && isset($this->domainName)) { $domainName = $this->domainName; } elseif (strpos($this->email, '@')) { list($local, $domainName) = explode('@', $this->email); } else { return null; } return \App\Domain::withTrashed()->where('namespace', $domainName)->first(); } /** * Find whether an email address exists as a model object (including soft-deleted). * * @param string $email Email address * @param bool $return_object Return model instance instead of a boolean * * @return static|bool True or Model object if found, False otherwise */ public static function emailExists(string $email, bool $return_object = false) { if (strpos($email, '@') === false) { return false; } $email = \strtolower($email); $object = static::withTrashed()->where('email', $email)->first(); if ($object) { return $return_object ? $object : true; } return false; } /** * Ensure the email is appropriately cased. * * @param string $email Email address */ public function setEmailAttribute(string $email): void { $this->attributes['email'] = strtolower($email); } } diff --git a/src/phpstan.neon b/src/phpstan.neon index 01dfa085..73729dfe 100644 --- a/src/phpstan.neon +++ b/src/phpstan.neon @@ -1,20 +1,17 @@ includes: - ./vendor/larastan/larastan/extension.neon parameters: ignoreErrors: - '#Access to an undefined property [a-zA-Z\\]+::\$pivot#' - - '#Call to an undefined [a-zA-Z0-9<>\\ ]+::withEnvTenantContext\(\)#' - - '#Call to an undefined [a-zA-Z0-9<>\\ ]+::withObjectTenantContext\(\)#' - - '#Call to an undefined [a-zA-Z0-9<>\\ ]+::withSubjectTenantContext\(\)#' - '#Call to an undefined method Tests\\Browser::#' level: 5 parallel: processTimeout: 300.0 paths: - app/ - config/ - database/ - resources/ - routes/ - tests/ - resources/