Skip to content

Commit

Permalink
Added @throws PHPDoc.
Browse files Browse the repository at this point in the history
  • Loading branch information
SidRoberts committed Sep 13, 2023
1 parent 152f041 commit 9cdb2a5
Show file tree
Hide file tree
Showing 44 changed files with 237 additions and 7 deletions.
7 changes: 7 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
findUnusedBaselineEntry="true"
findUnusedCode="false"
findUnusedVariablesAndParams="true"
checkForThrowsDocblock="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
Expand All @@ -22,6 +23,12 @@
</ignoreFiles>
</projectFiles>
<issueHandlers>
<MissingThrowsDocblock>
<errorLevel type="suppress">
<directory name="src/Codeception/Actions"/>
<directory name="tests"/>
</errorLevel>
</MissingThrowsDocblock>
</issueHandlers>
<plugins>
<pluginClass class="Psalm\MockeryPlugin\Plugin"/>
Expand Down
3 changes: 3 additions & 0 deletions src/Access/Access.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public function isAllowed(string $user, string $activityName): bool
return $activity->isAllowed($user);
}

/**
* @throws AccessDeniedException
*/
public function verify(string $user, string $activityName): void
{
if (!$this->isAllowed($user, $activityName)) {
Expand Down
9 changes: 8 additions & 1 deletion src/Codeception/Actions/ConsoleActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,16 @@ public function addConsoleExceptionHandler(string $exceptionHandlerClass): void



/**
* @throws ModuleException
*/
public function grabExitCode(): int
{
return $this->exitCode ?? throw new ModuleException($this, "Command hasn't been executed yet.");
if ($this->exitCode === null) {
throw new ModuleException($this, "Command hasn't been executed yet.");
}

return $this->exitCode;
}

public function seeExitCodeIs(int $expectedCode): void
Expand Down
13 changes: 13 additions & 0 deletions src/Codeception/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class Module extends CodeceptionModule
* @param array<mixed> $settings
*
* @return void
*
* @throws Exception
* @throws TypeError
*/
public function _beforeSuite(array $settings = [])
{
Expand All @@ -41,6 +44,9 @@ public function _beforeSuite(array $settings = [])

/**
* @return void
*
* @throws Exception
* @throws TypeError
*/
public function _before(TestInterface $test)
{
Expand Down Expand Up @@ -69,6 +75,10 @@ public function _afterSuite()



/**
* @throws Exception
* @throws TypeError
*/
public function makeNewContainer(): void
{
$containerFile = Configuration::projectDir() . $this->config["container"];
Expand Down Expand Up @@ -100,6 +110,9 @@ public function makeNewContainer(): void



/**
* @throws ContainerNotFoundException
*/
public function grabContainer(): ContainerInterface
{
if (!$this->container) {
Expand Down
27 changes: 25 additions & 2 deletions src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class Application implements ApplicationInterface



/**
* @throws CommandMetadataNotFoundException
*/
public function __construct(
protected readonly ContainerInterface $container,
) {
Expand All @@ -41,20 +44,29 @@ public function __construct(

/**
* @param class-string<CommandInterface> $commandClass
*
* @throws CommandMetadataNotFoundException
*/
public function getCommandMetadata(string $commandClass): CommandMetadata
{
$reflectionClass = new ReflectionClass($commandClass);

$attributes = $reflectionClass->getAttributes(CommandMetadata::class);

$attribute = $attributes[0] ?? throw new CommandMetadataNotFoundException($commandClass);
if (count($attributes) === 0) {
throw new CommandMetadataNotFoundException($commandClass);
}

$attribute = $attributes[0];

return $attribute->newInstance();
}



/**
* @throws CommandMetadataNotFoundException
*/
public function addCommand(string $commandClass): void
{
$metadata = $this->getCommandMetadata($commandClass);
Expand All @@ -78,6 +90,10 @@ public function addExceptionHandler(string $exceptionHandlerClass): void



/**
* @throws Throwable
* @throws CommandNotFoundException
*/
public function handle(TerminalInterface $terminal): int
{
$arguments = $terminal->getArguments();
Expand All @@ -90,7 +106,11 @@ public function handle(TerminalInterface $terminal): int

$name = $arguments->getCommandName();

$commandClass = $this->commands[$name] ?? throw new CommandNotFoundException($name);
if (!isset($this->commands[$name])) {
throw new CommandNotFoundException($name);
}

$commandClass = $this->commands[$name];

$command = $this->container->get($commandClass);

Expand All @@ -103,6 +123,9 @@ public function handle(TerminalInterface $terminal): int
}
}

/**
* @throws Throwable
*/
protected function handleException(TerminalInterface $terminal, Throwable $throwable): int
{
foreach ($this->exceptionHandlers as $exceptionHandlerClass) {
Expand Down
3 changes: 3 additions & 0 deletions src/Console/CommandMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#[Attribute(Attribute::TARGET_CLASS)]
class CommandMetadata
{
/**
* @throws InvalidCommandNameException
*/
public function __construct(
protected readonly string $name,
protected readonly string $description = ""
Expand Down
6 changes: 6 additions & 0 deletions src/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public function getServiceStorage(): ServiceStorageInterface
* @param class-string<T> $class
*
* @return T
*
* @throws InstantiateInterfaceException
*/
public function get(string $class): object
{
Expand Down Expand Up @@ -95,6 +97,8 @@ public function get(string $class): object
* @param class-string<ServiceInterface<T>> $serviceClass
*
* @return T
*
* @throws InstantiateInterfaceException
*/
public function typehintService(string $serviceClass): object
{
Expand All @@ -111,6 +115,8 @@ public function typehintService(string $serviceClass): object
* @param class-string<T> $class
*
* @return T
*
* @throws InstantiateInterfaceException
*/
public function typehintClass(string $class): object
{
Expand Down
3 changes: 3 additions & 0 deletions src/Container/Resolver/ConsoleResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public function __construct(



/**
* @throws UnresolvableParameterException
*/
public function resolve(ReflectionParameter $parameter): mixed
{
$declaringClass = $parameter->getDeclaringClass();
Expand Down
4 changes: 4 additions & 0 deletions src/Container/Resolver/FormResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public function __construct(



/**
* @throws UnresolvableParameterException
* @throws FormFieldNotFoundException
*/
public function resolve(ReflectionParameter $parameter): mixed
{
$declaringClass = $parameter->getDeclaringClass();
Expand Down
5 changes: 5 additions & 0 deletions src/Container/Resolver/RequestResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public function __construct(



/**
* @throws UnresolvableParameterException
* @throws CookieNotFoundException
* @throws FileGroupNotFoundException
*/
public function resolve(ReflectionParameter $parameter): mixed
{
$declaringClass = $parameter->getDeclaringClass();
Expand Down
3 changes: 3 additions & 0 deletions src/Container/Resolver/RouterParametersResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public function __construct(



/**
* @throws UnresolvableParameterException
*/
public function resolve(ReflectionParameter $parameter): mixed
{
$declaringClass = $parameter->getDeclaringClass();
Expand Down
3 changes: 3 additions & 0 deletions src/Container/ResolverGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public function remove(ResolverInterface $resolver): void



/**
* @throws UnresolvableParameterException
*/
public function resolve(ReflectionParameter $parameter, ContainerInterface $container): mixed
{
foreach ($this->resolvers as $resolver) {
Expand Down
4 changes: 4 additions & 0 deletions src/Cron/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Cron\CronExpression;
use DateTimeImmutable;
use DateTimeInterface;
use InvalidArgumentException;

class Cron implements CronInterface
{
Expand Down Expand Up @@ -41,6 +42,9 @@ public function getAllJobs(): array



/**
* @throws InvalidArgumentException
*/
protected function isDue(JobInterface $job, DateTimeInterface $datetime = null): bool
{
$cronExpression = new CronExpression(
Expand Down
2 changes: 2 additions & 0 deletions src/Filter/Cast/ToArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class ToArray implements FilterInterface
{
/**
* @return array<mixed>
*
* @throws UnexpectedValueException
*/
public function filter(mixed $value): array
{
Expand Down
3 changes: 3 additions & 0 deletions src/Filter/Cast/ToInteger.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

class ToInteger implements FilterInterface
{
/**
* @throws InvalidArgumentException
*/
public function filter(mixed $value): int
{
if (!is_array($value) && !is_resource($value) && !is_null($value) && !is_scalar($value)) {
Expand Down
4 changes: 4 additions & 0 deletions src/Filter/Cast/ToString.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

class ToString implements FilterInterface
{
/**
* @throws JsonException
* @throws InvalidArgumentException
*/
public function filter(mixed $value): string
{
if (is_object($value) && !method_exists($value, "__toString")) {
Expand Down
4 changes: 4 additions & 0 deletions src/Filter/String/Alpha.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
*/
class Alpha implements FilterInterface
{
/**
* @throws InvalidArgumentException
* @throws Exception
*/
public function filter(mixed $value): string
{
if (!is_string($value)) {
Expand Down
4 changes: 4 additions & 0 deletions src/Filter/String/Alphanumeric.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
*/
class Alphanumeric implements FilterInterface
{
/**
* @throws InvalidArgumentException
* @throws Exception
*/
public function filter(mixed $value): string
{
if (!is_string($value)) {
Expand Down
3 changes: 3 additions & 0 deletions src/Filter/String/Base64Decode.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
*/
class Base64Decode implements FilterInterface
{
/**
* @throws InvalidArgumentException
*/
public function filter(mixed $value): string
{
if (!is_string($value)) {
Expand Down
3 changes: 3 additions & 0 deletions src/Filter/String/Base64Encode.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
*/
class Base64Encode implements FilterInterface
{
/**
* @throws InvalidArgumentException
*/
public function filter(mixed $value): string
{
if (!is_string($value)) {
Expand Down
3 changes: 3 additions & 0 deletions src/Filter/String/CamelCaseToSlug.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

class CamelCaseToSlug implements FilterInterface
{
/**
* @throws InvalidArgumentException
*/
public function filter(mixed $value): string
{
if (!is_string($value)) {
Expand Down
3 changes: 3 additions & 0 deletions src/Filter/String/Prefix.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public function __construct(



/**
* @throws InvalidArgumentException
*/
public function filter(mixed $value): string
{
if (!is_string($value)) {
Expand Down
3 changes: 3 additions & 0 deletions src/Filter/String/Replace.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public function __construct(



/**
* @throws InvalidArgumentException
*/
public function filter(mixed $value): string
{
if (!is_string($value)) {
Expand Down
3 changes: 3 additions & 0 deletions src/Filter/String/Rot13.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
*/
class Rot13 implements FilterInterface
{
/**
* @throws InvalidArgumentException
*/
public function filter(mixed $value): string
{
if (!is_string($value)) {
Expand Down
3 changes: 3 additions & 0 deletions src/Filter/String/SlugToCamelCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

class SlugToCamelCase implements FilterInterface
{
/**
* @throws InvalidArgumentException
*/
public function filter(mixed $value): string
{
if (!is_string($value)) {
Expand Down
Loading

0 comments on commit 9cdb2a5

Please sign in to comment.