Skip to content

Commit

Permalink
migrate routes to attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
garak committed Apr 26, 2024
1 parent 7daf1bf commit dbbdc10
Show file tree
Hide file tree
Showing 32 changed files with 130 additions and 152 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"m4tthumphrey/php-gitlab-api": "^11.8",
"php-http/guzzle6-adapter": "^2.0",
"predis/predis": "^2.2",
"sentry/sentry-symfony": "^4.13",
"sentry/sentry-symfony": "^5.0",
"snc/redis-bundle": "^4.7",
"symfony/asset": "^7.0",
"symfony/console": "^7.0",
Expand Down
11 changes: 2 additions & 9 deletions config/packages/sentry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,5 @@ sentry:
capture_soft_fails: true # captures exceptions marked for retry too
options:
environment: '%kernel.environment%'
integrations:
- 'Sentry\Integration\IgnoreErrorsIntegration'

services:
Sentry\Integration\IgnoreErrorsIntegration:
arguments:
$options:
ignore_exceptions:
- Symfony\Component\HttpKernel\Exception\NotFoundHttpException
ignore_exceptions:
- Symfony\Component\HttpKernel\Exception\NotFoundHttpException
27 changes: 3 additions & 24 deletions config/routes.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
home:
path: /
controller: App\Controller\HomeController::index
defaults:
repository: "phpunit/phpunit"

health:
path: /health
controller: App\Controller\HealthController::health

show:
path: /show/{repository}
controller: App\Controller\HomeController::index
requirements:
repository: '[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?'

snippet_all:
path: /snippet/all/
defaults: { _controller: 'App\Controller\SnippetController::all' }
controllers:
resource: ../src/Controller/
type: attribute

pugx_badge_packagist:
path: /packages/{repository}
Expand All @@ -25,11 +9,6 @@ pugx_badge_packagist:
requirements:
repository: "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+"

search_packagist:
path: /search_packagist
controller: App\Controller\PackagistController::search
methods: [GET]

# https://circleci.com/api/v1.1/project/github/PUGX/badge-poser?filter=completed&limit=1
# https://circleci.com/api/v1.1/project/github/PUGX/badge-poser/tree/release%2Fv3.0.0?filter=completed&limit=1
circleci_api_repository:
Expand Down
4 changes: 2 additions & 2 deletions src/Badge/Model/Badge.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

final class Badge implements BadgeInterface, \Stringable
{
public const DEFAULT_FORMAT = 'svg';
public const DEFAULT_STYLE = \PUGX\Poser\Badge::DEFAULT_STYLE;
public const string DEFAULT_FORMAT = 'svg';
public const string DEFAULT_STYLE = \PUGX\Poser\Badge::DEFAULT_STYLE;

private string $subject;
private string $status;
Expand Down
12 changes: 6 additions & 6 deletions src/Badge/Model/CacheableBadge.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
*/
final class CacheableBadge implements BadgeInterface, \Stringable
{
public const TTL_NO_CACHE = 0;
public const TTL_ONE_HOUR = 60 * 60;
public const TTL_SIX_HOURS = 6 * self::TTL_ONE_HOUR;
public const TTL_TWELVE_HOURS = 12 * self::TTL_ONE_HOUR;
public const TTL_ONE_DAY = 24 * self::TTL_ONE_HOUR;
public const TTL_ONE_WEEK = 7 * self::TTL_ONE_DAY;
public const int TTL_NO_CACHE = 0;
public const int TTL_ONE_HOUR = 60 * 60;
public const int TTL_SIX_HOURS = 6 * self::TTL_ONE_HOUR;
public const int TTL_TWELVE_HOURS = 12 * self::TTL_ONE_HOUR;
public const int TTL_ONE_DAY = 24 * self::TTL_ONE_HOUR;
public const int TTL_ONE_WEEK = 7 * self::TTL_ONE_DAY;

public function __construct(private readonly BadgeInterface $badge, private int $maxage, private int $smaxage)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Badge/Model/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
/**
* An Image value Object.
*/
final class Image implements \Stringable
final readonly class Image implements \Stringable
{
private function __construct(
private readonly string $name,
private readonly string $content,
private readonly string $format,
private string $name,
private string $content,
private string $format,
) {
}

Expand Down
16 changes: 8 additions & 8 deletions src/Badge/Model/UseCase/CreateCircleCiBadge.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
*/
final class CreateCircleCiBadge extends BaseCreatePackagistImage
{
private const COLOR_PASSING = '42BD1B';
private const COLOR_FAILING = 'D75B48';
private const TEXT_PASSING = 'passing';
private const TEXT_FAILING = 'failing';
private const SUBJECT = 'build';

private const TTL_DEFAULT_MAXAGE = CacheableBadge::TTL_ONE_HOUR;
private const TTL_DEFAULT_SMAXAGE = CacheableBadge::TTL_ONE_HOUR;
private const string COLOR_PASSING = '42BD1B';
private const string COLOR_FAILING = 'D75B48';
private const string TEXT_PASSING = 'passing';
private const string TEXT_FAILING = 'failing';
private const string SUBJECT = 'build';

private const int TTL_DEFAULT_MAXAGE = CacheableBadge::TTL_ONE_HOUR;
private const int TTL_DEFAULT_SMAXAGE = CacheableBadge::TTL_ONE_HOUR;

protected string $text = self::SUBJECT;

Expand Down
24 changes: 12 additions & 12 deletions src/Badge/Model/UseCase/CreateComposerLockBadge.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@
*/
final class CreateComposerLockBadge extends BaseCreatePackagistImage
{
private const COLOR_COMMITTED = 'e60073';
private const COLOR_UNCOMMITTED = '99004d';
private const COLOR_ERROR = 'aa0000';
private const LOCK_COMMITTED = 'committed';
private const LOCK_UNCOMMITTED = 'uncommitted';
private const LOCK_ERROR = 'checking';
private const SUBJECT = '.lock';
private const SUBJECT_ERROR = 'Error';
private const TIMEOUT_SECONDS = 8;
private const CONNECT_TIMEOUT_SECONDS = 5;
private const string COLOR_COMMITTED = 'e60073';
private const string COLOR_UNCOMMITTED = '99004d';
private const string COLOR_ERROR = 'aa0000';
private const string LOCK_COMMITTED = 'committed';
private const string LOCK_UNCOMMITTED = 'uncommitted';
private const string LOCK_ERROR = 'checking';
private const string SUBJECT = '.lock';
private const string SUBJECT_ERROR = 'Error';
private const int TIMEOUT_SECONDS = 8;
private const int CONNECT_TIMEOUT_SECONDS = 5;

private const TTL_DEFAULT_MAXAGE = CacheableBadge::TTL_ONE_HOUR;
private const TTL_DEFAULT_SMAXAGE = CacheableBadge::TTL_ONE_HOUR;
private const int TTL_DEFAULT_MAXAGE = CacheableBadge::TTL_ONE_HOUR;
private const int TTL_DEFAULT_SMAXAGE = CacheableBadge::TTL_ONE_HOUR;

protected string $text = self::LOCK_ERROR;

Expand Down
8 changes: 4 additions & 4 deletions src/Badge/Model/UseCase/CreateDependentsBadge.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
*/
final class CreateDependentsBadge extends BaseCreatePackagistImage
{
public const COLOR = '007ec6';
public const SUBJECT = 'dependents';
public const string COLOR = '007ec6';
public const string SUBJECT = 'dependents';

private const TTL_DEFAULT_MAXAGE = CacheableBadge::TTL_ONE_HOUR;
private const TTL_DEFAULT_SMAXAGE = CacheableBadge::TTL_ONE_HOUR;
private const int TTL_DEFAULT_MAXAGE = CacheableBadge::TTL_ONE_HOUR;
private const int TTL_DEFAULT_SMAXAGE = CacheableBadge::TTL_ONE_HOUR;

private NormalizerInterface $normalizer;

Expand Down
8 changes: 4 additions & 4 deletions src/Badge/Model/UseCase/CreateDownloadsBadge.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
*/
final class CreateDownloadsBadge extends BaseCreatePackagistImage
{
private const COLOR = '007ec6';
private const SUBJECT = 'downloads';
private const string COLOR = '007ec6';
private const string SUBJECT = 'downloads';

private const TTL_DEFAULT_MAXAGE = CacheableBadge::TTL_ONE_HOUR;
private const TTL_DEFAULT_SMAXAGE = CacheableBadge::TTL_ONE_HOUR;
private const int TTL_DEFAULT_MAXAGE = CacheableBadge::TTL_ONE_HOUR;
private const int TTL_DEFAULT_SMAXAGE = CacheableBadge::TTL_ONE_HOUR;

private NormalizerInterface $normalizer;

Expand Down
12 changes: 6 additions & 6 deletions src/Badge/Model/UseCase/CreateErrorBadge.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
*/
final class CreateErrorBadge
{
private const COLOR = 'e05d44';
private const ERROR_TEXT_GENERIC = 'generic';
private const ERROR_TEXT_CLIENT_EXCEPTION = 'connection';
private const ERROR_TEXT_CLIENT_BAD_RESPONSE = 'not found?';
private const string COLOR = 'e05d44';
private const string ERROR_TEXT_GENERIC = 'generic';
private const string ERROR_TEXT_CLIENT_EXCEPTION = 'connection';
private const string ERROR_TEXT_CLIENT_BAD_RESPONSE = 'not found?';

private const TTL_DEFAULT_MAXAGE = CacheableBadge::TTL_NO_CACHE;
private const TTL_DEFAULT_SMAXAGE = CacheableBadge::TTL_NO_CACHE;
private const int TTL_DEFAULT_MAXAGE = CacheableBadge::TTL_NO_CACHE;
private const int TTL_DEFAULT_SMAXAGE = CacheableBadge::TTL_NO_CACHE;

/**
* @throws \InvalidArgumentException
Expand Down
24 changes: 12 additions & 12 deletions src/Badge/Model/UseCase/CreateGitAttributesBadge.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@
*/
final class CreateGitAttributesBadge extends BaseCreatePackagistImage
{
private const COLOR_COMMITTED = '96d490';
private const COLOR_UNCOMMITTED = 'ad6c4b';
private const COLOR_ERROR = 'aa0000';
private const GITATTRIBUTES_COMMITTED = 'committed';
private const GITATTRIBUTES_UNCOMMITTED = 'uncommitted';
private const GITATTRIBUTES_ERROR = 'checking';
private const SUBJECT = '.gitattributes';
private const SUBJECT_ERROR = 'Error';
private const TIMEOUT_SECONDS = 8;
private const CONNECT_TIMEOUT_SECONDS = 5;
private const string COLOR_COMMITTED = '96d490';
private const string COLOR_UNCOMMITTED = 'ad6c4b';
private const string COLOR_ERROR = 'aa0000';
private const string GITATTRIBUTES_COMMITTED = 'committed';
private const string GITATTRIBUTES_UNCOMMITTED = 'uncommitted';
private const string GITATTRIBUTES_ERROR = 'checking';
private const string SUBJECT = '.gitattributes';
private const string SUBJECT_ERROR = 'Error';
private const int TIMEOUT_SECONDS = 8;
private const int CONNECT_TIMEOUT_SECONDS = 5;

private const TTL_DEFAULT_MAXAGE = CacheableBadge::TTL_ONE_HOUR;
private const TTL_DEFAULT_SMAXAGE = CacheableBadge::TTL_ONE_HOUR;
private const int TTL_DEFAULT_MAXAGE = CacheableBadge::TTL_ONE_HOUR;
private const int TTL_DEFAULT_SMAXAGE = CacheableBadge::TTL_ONE_HOUR;

protected string $text = self::GITATTRIBUTES_ERROR;

Expand Down
10 changes: 5 additions & 5 deletions src/Badge/Model/UseCase/CreateLicenseBadge.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
*/
final class CreateLicenseBadge extends BaseCreatePackagistImage
{
private const COLOR = '428F7E';
private const SUBJECT = 'license';
private const TEXT_NO_LICENSE = 'no';
private const string COLOR = '428F7E';
private const string SUBJECT = 'license';
private const string TEXT_NO_LICENSE = 'no';

private const TTL_DEFAULT_MAXAGE = CacheableBadge::TTL_ONE_HOUR;
private const TTL_DEFAULT_SMAXAGE = CacheableBadge::TTL_ONE_HOUR;
private const int TTL_DEFAULT_MAXAGE = CacheableBadge::TTL_ONE_HOUR;
private const int TTL_DEFAULT_SMAXAGE = CacheableBadge::TTL_ONE_HOUR;

/**
* @throws \InvalidArgumentException
Expand Down
8 changes: 4 additions & 4 deletions src/Badge/Model/UseCase/CreateRequireBadge.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
*/
final class CreateRequireBadge extends BaseCreatePackagistImage
{
public const COLOR = '787CB5';
public const TEXT_NO_REQUIRE = ' - ';
public const string COLOR = '787CB5';
public const string TEXT_NO_REQUIRE = ' - ';

private const TTL_DEFAULT_MAXAGE = CacheableBadge::TTL_ONE_HOUR;
private const TTL_DEFAULT_SMAXAGE = CacheableBadge::TTL_ONE_HOUR;
private const int TTL_DEFAULT_MAXAGE = CacheableBadge::TTL_ONE_HOUR;
private const int TTL_DEFAULT_SMAXAGE = CacheableBadge::TTL_ONE_HOUR;

public function createRequireBadge(string $repository, string $type, string $format = Badge::DEFAULT_FORMAT, string $style = Badge::DEFAULT_STYLE): CacheableBadge
{
Expand Down
8 changes: 4 additions & 4 deletions src/Badge/Model/UseCase/CreateSuggestersBadge.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
*/
final class CreateSuggestersBadge extends BaseCreatePackagistImage
{
public const COLOR = '007ec6';
public const SUBJECT = 'suggesters';
public const string COLOR = '007ec6';
public const string SUBJECT = 'suggesters';

private const TTL_DEFAULT_MAXAGE = CacheableBadge::TTL_ONE_HOUR;
private const TTL_DEFAULT_SMAXAGE = CacheableBadge::TTL_ONE_HOUR;
private const int TTL_DEFAULT_MAXAGE = CacheableBadge::TTL_ONE_HOUR;
private const int TTL_DEFAULT_SMAXAGE = CacheableBadge::TTL_ONE_HOUR;

private NormalizerInterface $normalizer;

Expand Down
14 changes: 7 additions & 7 deletions src/Badge/Model/UseCase/CreateVersionBadge.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
*/
final class CreateVersionBadge extends BaseCreatePackagistImage
{
private const COLOR_STABLE = '28a3df';
private const COLOR_UNSTABLE = 'e68718';
private const SUBJECT_STABLE = 'stable';
private const SUBJECT_UNSTABLE = 'unstable';
private const TEXT_NO_STABLE_RELEASE = 'No Release';
private const string COLOR_STABLE = '28a3df';
private const string COLOR_UNSTABLE = 'e68718';
private const string SUBJECT_STABLE = 'stable';
private const string SUBJECT_UNSTABLE = 'unstable';
private const string TEXT_NO_STABLE_RELEASE = 'No Release';

private const TTL_DEFAULT_MAXAGE = CacheableBadge::TTL_ONE_HOUR;
private const TTL_DEFAULT_SMAXAGE = CacheableBadge::TTL_ONE_HOUR;
private const int TTL_DEFAULT_MAXAGE = CacheableBadge::TTL_ONE_HOUR;
private const int TTL_DEFAULT_SMAXAGE = CacheableBadge::TTL_ONE_HOUR;

/**
* @throws \InvalidArgumentException
Expand Down
6 changes: 3 additions & 3 deletions src/Badge/Service/ClientStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

final class ClientStrategy
{
private const GITHUB_REPOSITORY_PREFIX = 'blob';
private const BITBUCKET_REPOSITORY_PREFIX = 'src';
private const GITLAB_REPOSITORY_PREFIX = 'blob';
private const string GITHUB_REPOSITORY_PREFIX = 'blob';
private const string BITBUCKET_REPOSITORY_PREFIX = 'src';
private const string GITLAB_REPOSITORY_PREFIX = 'blob';

public function __construct(
private readonly GithubClient $githubClient,
Expand Down
6 changes: 3 additions & 3 deletions src/Badge/Service/ImageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
/**
* Class ImageFactory.
*/
final class ImageFactory
final readonly class ImageFactory
{
public function __construct(
private readonly Poser $generator,
private readonly EventDispatcherInterface $eventDispatcher,
private Poser $generator,
private EventDispatcherInterface $eventDispatcher,
) {
}

Expand Down
14 changes: 7 additions & 7 deletions src/Badge/ValueObject/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

namespace App\Badge\ValueObject;

final class Repository
final readonly class Repository
{
private const GITHUB_SOURCE = 'github.com';
private const string GITHUB_SOURCE = 'github.com';

private const BITBUCKET_SOURCE = 'bitbucket.org';
private const string BITBUCKET_SOURCE = 'bitbucket.org';

private const GITLAB_SOURCE = 'gitlab.com';
private const string GITLAB_SOURCE = 'gitlab.com';

private function __construct(
private readonly string $source,
private readonly string $username,
private readonly string $name,
private string $source,
private string $username,
private string $name,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Contributors/Model/Contributor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

final class Contributor implements \Stringable
{
private const DEFAULT_IMG_SIZE = 160;
private const int DEFAULT_IMG_SIZE = 160;

private function __construct(
private readonly string $username,
Expand Down
Loading

0 comments on commit dbbdc10

Please sign in to comment.