Commit 1540157a authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

Met à jour les signatures de méthode vers PHP 7.1.

Showing with 58 additions and 138 deletions
+58 -138
......@@ -39,23 +39,23 @@ final class ComposerPackage implements ComposerPackageInterface
/**
* {@inheritdoc}
*/
public function getName()
public function getName(): string
{
return $this->getKey('name');
return $this->getKey('name', '');
}
/**
* {@inheritdoc}
*/
public function getDescription()
public function getDescription(): string
{
return $this->getKey('description');
return $this->getKey('description', '');
}
/**
* {@inheritdoc}
*/
public function getRequiredPHPVersion()
public function getRequiredPHPVersion(): float
{
$require = $this->getKey('require', []);
if (
......@@ -71,7 +71,7 @@ final class ComposerPackage implements ComposerPackageInterface
/**
* {@inheritdoc}
*/
public function getLicenses()
public function getLicenses(): iterable
{
return (array) $this->getKey('license', 'proprietary');
}
......@@ -82,7 +82,7 @@ final class ComposerPackage implements ComposerPackageInterface
*
* @throws \Assert\AssertionFailedException
*
* @return mixed|null
* @return mixed|string|number|null
*/
private function getKey($key, $default = null)
{
......@@ -93,20 +93,15 @@ final class ComposerPackage implements ComposerPackageInterface
return \array_key_exists($key, $data) ? $data[$key] : $default;
}
/**
* @return array
*/
private function getComposerJson()
private function getComposerJson(): array
{
return $this->composerJson !== null ? $this->composerJson : $this->readComposerJson();
}
/**
* @throws \Assert\AssertionFailedException
*
* @return array
*/
private function readComposerJson()
private function readComposerJson(): array
{
$composerPath = $this->fileLocator->locate('composer.json');
Assertion::notNull($composerPath, 'could not find composer.json');
......
......@@ -15,23 +15,11 @@ namespace Irstea\CS\Composer;
*/
interface ComposerPackageInterface
{
/**
* @return string
*/
public function getName();
public function getName(): string;
/**
* @return string
*/
public function getDescription();
public function getDescription(): string;
/**
* @return float
*/
public function getRequiredPHPVersion();
public function getRequiredPHPVersion(): float;
/**
* @return iterable
*/
public function getLicenses();
public function getLicenses(): iterable;
}
<?php
<?php declare(strict_types=1);
/*
* irstea/php-cs-fixer-config - Jeux de règles pour php-cs-fixer.
* Copyright (C) 2018-2019 IRSTEA
......@@ -46,13 +46,11 @@ final class Config extends PhpCsFixerConfig
/**
* Config constructor.
*
* @param string $name
*/
public function __construct(
ComposerPackageInterface $composerPackage,
HeaderProviderInterface $headerProvider,
$name = 'default'
string $name = 'default'
) {
parent::__construct($name);
......@@ -60,20 +58,10 @@ final class Config extends PhpCsFixerConfig
$this->headerProvider = $headerProvider;
}
/**
* Set docHeaderfile.
*
* @param string $docHeaderfile
*/
public function setDocHeaderfile($docHeaderfile)
{
$this->docHeaderfile = $docHeaderfile;
}
/**
* {@inheritdoc}
*/
public function getRules()
public function getRules(): array
{
$phpVersion = $this->composerPackage->getRequiredPHPVersion();
$risky = $this->getRiskyAllowed();
......@@ -85,13 +73,7 @@ final class Config extends PhpCsFixerConfig
);
}
/**
* @param float $phpVersion
* @param bool $risky
*
* @return array
*/
private function ruleSets($phpVersion, $risky)
private function ruleSets(float $phpVersion, bool $risky): array
{
return [
'@PSR2' => true,
......@@ -107,13 +89,7 @@ final class Config extends PhpCsFixerConfig
];
}
/**
* @param float $phpVersion
* @param bool $risky
*
* @return array
*/
public function baseRules($phpVersion, $risky)
public function baseRules(float $phpVersion, bool $risky): array
{
$rules = [
// Configuration && overrides
......@@ -163,7 +139,7 @@ final class Config extends PhpCsFixerConfig
* @param string $rule
* @param mixed $setting
*/
public function setRule($rule, $setting)
public function setRule($rule, $setting): void
{
$this->ruleOverrides[$rule] = $setting;
}
......@@ -171,7 +147,7 @@ final class Config extends PhpCsFixerConfig
/**
* {@inheritdoc}
*/
public function setRules(array $rules)
public function setRules(array $rules): void
{
$this->ruleOverrides = array_replace($this->ruleOverrides, $rules);
}
......@@ -179,7 +155,7 @@ final class Config extends PhpCsFixerConfig
/**
* {@inheritdoc}
*/
public static function create()
public static function create(): self
{
$stackTrace = debug_backtrace(1);
$callerPath = \dirname($stackTrace[0]['file']);
......
<?php
<?php declare(strict_types=1);
/*
* irstea/php-cs-fixer-config - Jeux de règles pour php-cs-fixer.
* Copyright (C) 2018-2019 IRSTEA
......@@ -27,9 +27,8 @@ final class ChainFileLocator implements FileLocatorInterface
*
* @param FileLocatorInterface[] $fileLocators
*/
public function __construct($fileLocators)
public function __construct(array $fileLocators)
{
Assertion::isArray($fileLocators);
Assertion::allImplementsInterface($fileLocators, FileLocatorInterface::class);
$this->fileLocators = $fileLocators;
......@@ -38,11 +37,11 @@ final class ChainFileLocator implements FileLocatorInterface
/**
* {@inheritdoc}
*/
public function locate($filename)
public function locate(string $filename): ?string
{
foreach ($this->fileLocators as $fileLocator) {
$result = $fileLocator->locate($filename);
if ($result !== null) {
if ($result) {
return $result;
}
}
......
<?php
<?php declare(strict_types=1);
/*
* irstea/php-cs-fixer-config - Jeux de règles pour php-cs-fixer.
* Copyright (C) 2018-2019 IRSTEA
......@@ -10,8 +10,6 @@
namespace Irstea\CS\FileLocator;
use Assert\Assertion;
/**
* Class FileLocator.
*/
......@@ -24,23 +22,17 @@ final class FileLocator implements FileLocatorInterface
/**
* FileLocator constructor.
*
* @param string $baseDir
*/
public function __construct($baseDir)
public function __construct(string $baseDir)
{
Assertion::string($baseDir);
$this->baseDir = rtrim($baseDir, \DIRECTORY_SEPARATOR) . \DIRECTORY_SEPARATOR;
}
/**
* {@inheritdoc}
*/
public function locate($filename)
public function locate(string $filename): ?string
{
Assertion::string($filename);
$path = $this->baseDir . ltrim($filename, \DIRECTORY_SEPARATOR);
if (!file_exists($path)) {
return null;
......
<?php
<?php declare(strict_types=1);
/*
* irstea/php-cs-fixer-config - Jeux de règles pour php-cs-fixer.
* Copyright (C) 2018-2019 IRSTEA
......@@ -15,10 +15,5 @@ namespace Irstea\CS\FileLocator;
*/
interface FileLocatorInterface
{
/**
* @param string $filename
*
* @return string|null
*/
public function locate($filename);
public function locate(string $filename): ?string;
}
......@@ -39,7 +39,7 @@ final class CachedGitRepository implements GitRepositoryInterface
/**
* {@inheritdoc}
*/
public function getHeadCommit()
public function getHeadCommit(): string
{
// Jamais mis en cache !
return $this->inner->getHeadCommit();
......@@ -48,7 +48,7 @@ final class CachedGitRepository implements GitRepositoryInterface
/**
* {@inheritdoc}
*/
public function getYearRange()
public function getYearRange(): string
{
return $this->cache->get('git.year-range', [$this->inner, 'getYearRange']);
}
......
......@@ -24,12 +24,9 @@ final class GitRepository implements GitRepositoryInterface
/**
* GitRepository constructor.
*
* @param string $repositoryPath
*/
public function __construct($repositoryPath)
public function __construct(string $repositoryPath)
{
Assertion::string($repositoryPath);
Assertion::directory($repositoryPath . '/.git');
$this->repositoryPath = $repositoryPath;
......@@ -38,7 +35,7 @@ final class GitRepository implements GitRepositoryInterface
/**
* {@inheritdoc}
*/
public function getHeadCommit()
public function getHeadCommit(): string
{
return trim(shell_exec('git -C ' . escapeshellarg($this->repositoryPath) . ' rev-parse HEAD'));
}
......@@ -46,7 +43,7 @@ final class GitRepository implements GitRepositoryInterface
/**
* {@inheritdoc}
*/
public function getYearRange()
public function getYearRange(): string
{
$last = date('Y');
$first = exec('git -C ' . escapeshellarg($this->repositoryPath) . ' log --format=%cd --date=format:%Y --date-order | tail -n1');
......
......@@ -15,13 +15,7 @@ namespace Irstea\CS\Git;
*/
interface GitRepositoryInterface
{
/**
* @return string
*/
public function getHeadCommit();
public function getHeadCommit(): string;
/**
* @return string
*/
public function getYearRange();
public function getYearRange(): string;
}
......@@ -27,9 +27,8 @@ final class ChainTemplateProvider implements TemplateProviderInterface
*
* @param TemplateProviderInterface[] $templateProviders
*/
public function __construct($templateProviders)
public function __construct(array $templateProviders)
{
Assertion::isArray($templateProviders);
Assertion::allImplementsInterface($templateProviders, TemplateProviderInterface::class);
$this->templateProviders = $templateProviders;
......@@ -38,7 +37,7 @@ final class ChainTemplateProvider implements TemplateProviderInterface
/**
* {@inheritdoc}
*/
public function getTemplate()
public function getTemplate(): ?string
{
foreach ($this->templateProviders as $templateProvider) {
$template = $templateProvider->getTemplate();
......
......@@ -37,7 +37,7 @@ final class FormattedHeaderProvider implements HeaderProviderInterface
/**
* {@inheritdoc}
*/
public function getHeader()
public function getHeader(): ?string
{
$template = $this->templateProvider->getTemplate();
......
<?php
<?php declare(strict_types=1);
/*
* irstea/php-cs-fixer-config - Jeux de règles pour php-cs-fixer.
* Copyright (C) 2018-2019 IRSTEA
......@@ -15,8 +15,5 @@ namespace Irstea\CS\HeaderComment;
*/
interface HeaderProviderInterface
{
/**
* @return string|null
*/
public function getHeader();
public function getHeader(): ?string;
}
......@@ -43,17 +43,14 @@ final class LicenseTemplateProvider implements TemplateProviderInterface
/**
* {@inheritdoc}
*/
public function getTemplate()
public function getTemplate(): ?string
{
$path = $this->getLicensePath();
return $path ? file_get_contents($path) : null;
}
/**
* @return string|null
*/
private function getLicensePath()
private function getLicensePath(): ?string
{
$licenses = $this->composerPackage->getLicenses();
if (!$licenses) {
......
......@@ -10,7 +10,6 @@
namespace Irstea\CS\HeaderComment;
use Assert\Assertion;
use Irstea\CS\Composer\ComposerPackageInterface;
use Irstea\CS\Git\GitRepositoryInterface;
......@@ -41,10 +40,8 @@ final class TemplateFormatter implements TemplateFormatterInterface
/**
* {@inheritdoc}
*/
public function format($template)
public function format(string $template): string
{
Assertion::string($template);
$variables = [
'%package%' => $this->composerPackage->getName(),
'%description%' => $this->composerPackage->getDescription(),
......
......@@ -15,10 +15,5 @@ namespace Irstea\CS\HeaderComment;
*/
interface TemplateFormatterInterface
{
/**
* @param string $template
*
* @return string
*/
public function format($template);
public function format(string $template): string;
}
......@@ -15,8 +15,5 @@ namespace Irstea\CS\HeaderComment;
*/
interface TemplateProviderInterface
{
/**
* @return string|null
*/
public function getTemplate();
public function getTemplate(): ?string;
}
<?php
<?php declare(strict_types=1);
/*
* irstea/php-cs-fixer-config - Jeux de règles pour php-cs-fixer.
* Copyright (C) 2018-2019 IRSTEA
......@@ -33,8 +33,10 @@ final class UserDefinedTemplateProvider implements TemplateProviderInterface
/**
* {@inheritdoc}
*/
public function getTemplate()
public function getTemplate(): ?string
{
return $this->fileLocator->locate('.docheader');
$path = $this->fileLocator->locate('.docheader');
return $path ? file_get_contents($path) : null;
}
}
......@@ -19,7 +19,7 @@ use PHPUnit\Framework\TestCase;
*/
class FileLocatorTest extends TestCase
{
public function testShouldLocateExistingFile()
public function testShouldLocateExistingFile(): void
{
$fs = vfsStream::setup('root', 0755, [
'file' => 'content',
......@@ -33,7 +33,7 @@ class FileLocatorTest extends TestCase
);
}
public function testShouldReturnNullOnMissingFile()
public function testShouldReturnNullOnMissingFile(): void
{
$fs = vfsStream::setup();
$locator = new FileLocator($fs->url());
......
<?php
<?php declare(strict_types=1);
/*
* irstea/php-cs-fixer-config - Jeux de règles pour php-cs-fixer.
* Copyright (C) 2018-2019 IRSTEA
......@@ -69,7 +69,7 @@ final class LicenseTemplateProviderTest extends TestCase
);
}
public function testShouldProvideKnownLicenseHeader()
public function testShouldProvideKnownLicenseHeader(): void
{
$this->composerPackage->getLicenses()
->shouldBeCalled()
......@@ -78,7 +78,7 @@ final class LicenseTemplateProviderTest extends TestCase
self::assertEquals('GPL-template', $this->templateProvider->getTemplate());
}
public function testShouldProvideDefaultLicenseHeader()
public function testShouldProvideDefaultLicenseHeader(): void
{
$this->composerPackage->getLicenses()
->shouldBeCalled()
......@@ -87,7 +87,7 @@ final class LicenseTemplateProviderTest extends TestCase
self::assertEquals('default-template', $this->templateProvider->getTemplate());
}
public function testShouldProvideProprietaryLicenseHeaderWithNoLicense()
public function testShouldProvideProprietaryLicenseHeaderWithNoLicense(): void
{
$this->composerPackage->getLicenses()
->shouldBeCalled()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment