Skip to content

Commit

Permalink
Merge pull request #59 from AlessandroMinoccheri/improve-psalm-3-level
Browse files Browse the repository at this point in the history
upgrade to level 3 of psalm
  • Loading branch information
JellyBellyDev committed Oct 9, 2020
2 parents 080d389 + 90c4e47 commit df0704b
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 12 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [v2.0.4] - 2020-10-09

### Changed
* upgrade psalm error level to 3

## [v2.0.3] - 2020-10-08

### Changed
Expand Down Expand Up @@ -110,7 +115,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- stable release for poser


[Unreleased]: https://github.com/badges/poser/compare/v2.0.3...HEAD
[Unreleased]: https://github.com/badges/poser/compare/v2.0.4...HEAD
[v2.0.4]: https://github.com/badges/poser/tree/v2.0.3
[v2.0.3]: https://github.com/badges/poser/tree/v2.0.3
[v2.0.2]: https://github.com/badges/poser/tree/v2.0.2
[v2.0.1]: https://github.com/badges/poser/tree/v2.0.1
Expand Down
2 changes: 1 addition & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
errorLevel="3"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
Expand Down
5 changes: 5 additions & 0 deletions src/Badge.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public static function getColorNamesAvailable(): array
public static function fromURI(string $URI): self
{
$parsedURI = \parse_url($URI);

if (!isset($parsedURI['path'])) {
throw new \InvalidArgumentException('The URI given is not a valid URI' . $URI);
}

$path = $parsedURI['path'];
\parse_str($parsedURI['query'] ?? '', $query);

Expand Down
8 changes: 8 additions & 0 deletions src/Render/LocalSvgRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ abstract protected function getTemplateName(): string;
*/
private function getTemplate(string $style): string
{
if (null === $this->templatesDirectory) {
throw new \InvalidArgumentException('TemplateDirectory cannot be null');
}

$filepath = \sprintf('%s/%s.svg', $this->templatesDirectory, $style);

if (!\file_exists($filepath)) {
Expand All @@ -70,6 +74,10 @@ private function getTemplate(string $style): string

private function stringWidth(string $text): float
{
if (null === $this->textSizeCalculator) {
throw new \InvalidArgumentException('TextSizeCalculator cannot be null');
}

return $this->textSizeCalculator->calculateWidth($text);
}

Expand Down
21 changes: 13 additions & 8 deletions src/UI/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PUGX\Poser\Render\SvgFlatRender;
use PUGX\Poser\Render\SvgFlatSquareRender;
use PUGX\Poser\Render\SvgPlasticRender;
use PUGX\Poser\ValueObject\InputRequest;
use Symfony\Component\Console\Command\Command as BaseCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -83,20 +84,24 @@ protected function configure(): void

/**
* @throws \Exception
* @throws \InvalidArgumentException
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$subject = $input->getArgument('subject');
$status = $input->getArgument('status');
$color = $input->getArgument('color');
$style = (string) $input->getOption('style');
$format = (string) $input->getOption('format');
$inputRequest = InputRequest::createFromInput($input);

try {
$imageContent = $this->poser->generate($subject, $status, $color, $style, $format);
$imageContent = $this->poser->generate(
$inputRequest->getSubject(),
$inputRequest->getStatus(),
$inputRequest->getColor(),
$inputRequest->getStyle(),
$inputRequest->getFormat()
);

if ($input->getOption('path')) {
$this->storeImage($output, $input->getOption('path'), (string) $imageContent);
$path = $input->getOption('path');
if ($path && \is_string($path)) {
$this->storeImage($output, $path, (string) $imageContent);
} else {
$this->flushImage($output, (string) $imageContent);
}
Expand Down
11 changes: 9 additions & 2 deletions src/UI/SingleCommandApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,21 @@ class SingleCommandApplication extends Application
*
* @param Command $command The single (accessible) command for this application
* @param string $version The version of the application
*
* @throws \InvalidArgumentException
*/
public function __construct(Command $command, string $version = 'UNKNOWN')
{
parent::__construct($command->getName(), $version);
$commandName = $command->getName();
if (null === $commandName) {
throw new \InvalidArgumentException('command cannot be null');
}

parent::__construct($commandName, $version);

// Add the given command as single (accessible) command.
$this->add($command);
$this->commandName = (string) $command->getName();
$this->commandName = (string) $commandName;

// Override the Application's definition so that it does not
// require a command name as first argument.
Expand Down
86 changes: 86 additions & 0 deletions src/ValueObject/InputRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

declare(strict_types=1);

namespace PUGX\Poser\ValueObject;

use PUGX\Poser\Badge;
use Symfony\Component\Console\Input\InputInterface;

class InputRequest
{
private string $subject;

private string $status;

private string $color;

private string $style;

private string $format;

private function __construct(string $subject, string $status, string $color, string $style, string $format)
{
$this->subject = $subject;
$this->status = $status;
$this->color = $color;
$this->style = $style;
$this->format = $format;
}

public static function createFromInput(InputInterface $input): self
{
$subject = $input->getArgument('subject');
$status = $input->getArgument('status');
$color = $input->getArgument('color');
$style = $input->getOption('style');
$format = $input->getOption('format');

if (!\is_string($subject)) {
throw new \InvalidArgumentException('subject is not a string');
}

if (!\is_string($status)) {
throw new \InvalidArgumentException('status is not a string');
}

if (!\is_string($color)) {
throw new \InvalidArgumentException('color is not a string');
}

if (!\is_string($style)) {
throw new \InvalidArgumentException('style is not a string');
}

if (!\is_string($format)) {
$format = BADGE::DEFAULT_FORMAT;
}

return new self($subject, $status, $color, $style, $format);
}

public function getSubject(): string
{
return $this->subject;
}

public function getStatus(): string
{
return $this->status;
}

public function getColor(): string
{
return $this->color;
}

public function getStyle(): string
{
return $this->style;
}

public function getFormat(): string
{
return $this->format;
}
}

0 comments on commit df0704b

Please sign in to comment.