Skip to content

Commit

Permalink
Add type hint convert classes. (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw authored Jan 19, 2024
1 parent a728d63 commit 00616a6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
6 changes: 4 additions & 2 deletions src/Converter/SemverConverter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Foxy package.
*
Expand All @@ -16,9 +18,9 @@
*
* @author François Pluchino <[email protected]>
*/
class SemverConverter implements VersionConverterInterface
final class SemverConverter implements VersionConverterInterface
{
public function convertVersion($version)
public function convertVersion(string $version = null): string
{
if (\in_array($version, array(null, '', 'latest'), true)) {
return ('latest' === $version ? 'default || ' : '').'*';
Expand Down
46 changes: 21 additions & 25 deletions src/Converter/SemverUtil.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Foxy package.
*
Expand All @@ -23,11 +25,9 @@ abstract class SemverUtil
/**
* Converts the date or datetime version.
*
* @param string $version The version
*
* @return string
* @param string $version The version.
*/
public static function convertDateVersion($version)
public static function convertDateVersion(string $version): string
{
if (preg_match('/^\d{7,}\./', $version)) {
$pos = strpos($version, '.');
Expand All @@ -41,10 +41,8 @@ public static function convertDateVersion($version)
* Converts the version metadata.
*
* @param string $version
*
* @return string
*/
public static function convertVersionMetadata($version)
public static function convertVersionMetadata(string $version): string
{
if (preg_match_all(
self::createPattern('([a-zA-Z]+|(\-|\+)[a-zA-Z]+|(\-|\+)[0-9]+)'),
Expand All @@ -70,11 +68,11 @@ public static function convertVersionMetadata($version)
/**
* Creates a pattern with the version prefix pattern.
*
* @param string $pattern The pattern without '/'
* @param string $pattern The pattern without '/'.
*
* @return string The full pattern with '/'
* @return string The full pattern with '/'.
*/
public static function createPattern($pattern)
public static function createPattern(string $pattern): string
{
$numVer = '([0-9]+|x|\*)';
$numVer2 = '('.$numVer.'\.'.$numVer.')';
Expand All @@ -86,11 +84,11 @@ public static function createPattern($pattern)
/**
* Clean the wildcard in version.
*
* @param string $version The version
* @param string $version The version.
*
* @return string The cleaned version
* @return string The cleaned version.
*/
private static function cleanWildcard($version)
private static function cleanWildcard(string $version): string
{
while (false !== strpos($version, '.x.x')) {
$version = str_replace('.x.x', '.x', $version);
Expand All @@ -102,12 +100,12 @@ private static function cleanWildcard($version)
/**
* Clean the raw version.
*
* @param string $version The version
* @param array $matches The match of pattern asset version
* @param string $version The version.
* @param array $matches The match of pattern asset version.
*
* @return array The list of $type, $version and $end
* @return array The list of $type, $version and $end.
*/
private static function cleanVersion($version, array $matches)
private static function cleanVersion(string $version, array $matches): array
{
$end = substr($version, \strlen($matches[1][0][0]));
$version = $matches[1][0][0].'-';
Expand All @@ -128,12 +126,12 @@ private static function cleanVersion($version, array $matches)
/**
* Match the version.
*
* @param string $version
* @param string $type
* @param string $version The version.
* @param string $type The type of version.
*
* @return array The list of $version and $patchVersion
* @return array The list of $version and $patchVersion.
*/
private static function matchVersion($version, $type)
private static function matchVersion(string $version, string $type): array
{
$patchVersion = true;

Expand Down Expand Up @@ -172,11 +170,9 @@ private static function matchVersion($version, $type)
/**
* Convert the minor version of date.
*
* @param string $minor The minor version
*
* @return string
* @param string $minor The minor version.
*/
private static function convertDateMinorVersion($minor)
private static function convertDateMinorVersion(string $minor): string
{
$split = explode('.', $minor);
$minor = (int) $split[0];
Expand Down
6 changes: 4 additions & 2 deletions src/Converter/VersionConverterInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Foxy package.
*
Expand All @@ -21,9 +23,9 @@ interface VersionConverterInterface
/**
* Converts the asset version to composer version.
*
* @param string $version The asset version
* @param string|null $version The asset version
*
* @return string The composer version
*/
public function convertVersion($version);
public function convertVersion(string $version = null): string;
}

0 comments on commit 00616a6

Please sign in to comment.