From 1540157adf83ead8403b8003f4656685c5be73a3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Guillaume=20Perr=C3=A9al?= <guillaume.perreal@irstea.fr>
Date: Wed, 11 Dec 2019 16:05:05 +0100
Subject: [PATCH] =?UTF-8?q?Met=20=C3=A0=20jour=20les=20signatures=20de=20m?=
 =?UTF-8?q?=C3=A9thode=20vers=20PHP=207.1.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/Composer/ComposerPackage.php              | 23 +++++------
 src/Composer/ComposerPackageInterface.php     | 20 ++--------
 src/Config.php                                | 40 ++++---------------
 src/FileLocator/ChainFileLocator.php          |  9 ++---
 src/FileLocator/FileLocator.php               | 14 ++-----
 src/FileLocator/FileLocatorInterface.php      |  9 +----
 src/Git/CachedGitRepository.php               |  4 +-
 src/Git/GitRepository.php                     |  9 ++---
 src/Git/GitRepositoryInterface.php            | 10 +----
 src/HeaderComment/ChainTemplateProvider.php   |  5 +--
 src/HeaderComment/FormattedHeaderProvider.php |  2 +-
 src/HeaderComment/HeaderProviderInterface.php |  7 +---
 src/HeaderComment/LicenseTemplateProvider.php |  7 +---
 src/HeaderComment/TemplateFormatter.php       |  5 +--
 .../TemplateFormatterInterface.php            |  7 +---
 .../TemplateProviderInterface.php             |  5 +--
 .../UserDefinedTemplateProvider.php           |  8 ++--
 tests/FileLocator/FileLocatorTest.php         |  4 +-
 .../LicenseTemplateProviderTest.php           |  8 ++--
 19 files changed, 58 insertions(+), 138 deletions(-)

diff --git a/src/Composer/ComposerPackage.php b/src/Composer/ComposerPackage.php
index ef10f1a..15fc83b 100644
--- a/src/Composer/ComposerPackage.php
+++ b/src/Composer/ComposerPackage.php
@@ -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');
diff --git a/src/Composer/ComposerPackageInterface.php b/src/Composer/ComposerPackageInterface.php
index a6abdd9..40218d5 100644
--- a/src/Composer/ComposerPackageInterface.php
+++ b/src/Composer/ComposerPackageInterface.php
@@ -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;
 }
diff --git a/src/Config.php b/src/Config.php
index 1b69e7a..64998ad 100644
--- a/src/Config.php
+++ b/src/Config.php
@@ -1,4 +1,4 @@
-<?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']);
diff --git a/src/FileLocator/ChainFileLocator.php b/src/FileLocator/ChainFileLocator.php
index 74357b8..896751f 100644
--- a/src/FileLocator/ChainFileLocator.php
+++ b/src/FileLocator/ChainFileLocator.php
@@ -1,4 +1,4 @@
-<?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;
             }
         }
diff --git a/src/FileLocator/FileLocator.php b/src/FileLocator/FileLocator.php
index 88e3282..d33d599 100644
--- a/src/FileLocator/FileLocator.php
+++ b/src/FileLocator/FileLocator.php
@@ -1,4 +1,4 @@
-<?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;
diff --git a/src/FileLocator/FileLocatorInterface.php b/src/FileLocator/FileLocatorInterface.php
index 5a1fb82..cdf287a 100644
--- a/src/FileLocator/FileLocatorInterface.php
+++ b/src/FileLocator/FileLocatorInterface.php
@@ -1,4 +1,4 @@
-<?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;
 }
diff --git a/src/Git/CachedGitRepository.php b/src/Git/CachedGitRepository.php
index a643117..9587fd4 100644
--- a/src/Git/CachedGitRepository.php
+++ b/src/Git/CachedGitRepository.php
@@ -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']);
     }
diff --git a/src/Git/GitRepository.php b/src/Git/GitRepository.php
index db6357e..e18ee75 100644
--- a/src/Git/GitRepository.php
+++ b/src/Git/GitRepository.php
@@ -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');
diff --git a/src/Git/GitRepositoryInterface.php b/src/Git/GitRepositoryInterface.php
index 4ee3cf1..79cccdd 100644
--- a/src/Git/GitRepositoryInterface.php
+++ b/src/Git/GitRepositoryInterface.php
@@ -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;
 }
diff --git a/src/HeaderComment/ChainTemplateProvider.php b/src/HeaderComment/ChainTemplateProvider.php
index 52939e9..661dcb9 100644
--- a/src/HeaderComment/ChainTemplateProvider.php
+++ b/src/HeaderComment/ChainTemplateProvider.php
@@ -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();
diff --git a/src/HeaderComment/FormattedHeaderProvider.php b/src/HeaderComment/FormattedHeaderProvider.php
index e6df362..c2fa042 100644
--- a/src/HeaderComment/FormattedHeaderProvider.php
+++ b/src/HeaderComment/FormattedHeaderProvider.php
@@ -37,7 +37,7 @@ final class FormattedHeaderProvider implements HeaderProviderInterface
     /**
      * {@inheritdoc}
      */
-    public function getHeader()
+    public function getHeader(): ?string
     {
         $template = $this->templateProvider->getTemplate();
 
diff --git a/src/HeaderComment/HeaderProviderInterface.php b/src/HeaderComment/HeaderProviderInterface.php
index 51acfe7..21e00c3 100644
--- a/src/HeaderComment/HeaderProviderInterface.php
+++ b/src/HeaderComment/HeaderProviderInterface.php
@@ -1,4 +1,4 @@
-<?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;
 }
diff --git a/src/HeaderComment/LicenseTemplateProvider.php b/src/HeaderComment/LicenseTemplateProvider.php
index 2419045..6ce59de 100644
--- a/src/HeaderComment/LicenseTemplateProvider.php
+++ b/src/HeaderComment/LicenseTemplateProvider.php
@@ -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) {
diff --git a/src/HeaderComment/TemplateFormatter.php b/src/HeaderComment/TemplateFormatter.php
index b2be4e9..ca9729a 100644
--- a/src/HeaderComment/TemplateFormatter.php
+++ b/src/HeaderComment/TemplateFormatter.php
@@ -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(),
diff --git a/src/HeaderComment/TemplateFormatterInterface.php b/src/HeaderComment/TemplateFormatterInterface.php
index 330f2d2..6234e39 100644
--- a/src/HeaderComment/TemplateFormatterInterface.php
+++ b/src/HeaderComment/TemplateFormatterInterface.php
@@ -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;
 }
diff --git a/src/HeaderComment/TemplateProviderInterface.php b/src/HeaderComment/TemplateProviderInterface.php
index 1883fcb..227ced1 100644
--- a/src/HeaderComment/TemplateProviderInterface.php
+++ b/src/HeaderComment/TemplateProviderInterface.php
@@ -15,8 +15,5 @@ namespace Irstea\CS\HeaderComment;
  */
 interface TemplateProviderInterface
 {
-    /**
-     * @return string|null
-     */
-    public function getTemplate();
+    public function getTemplate(): ?string;
 }
diff --git a/src/HeaderComment/UserDefinedTemplateProvider.php b/src/HeaderComment/UserDefinedTemplateProvider.php
index 54c00cf..ccb24fb 100644
--- a/src/HeaderComment/UserDefinedTemplateProvider.php
+++ b/src/HeaderComment/UserDefinedTemplateProvider.php
@@ -1,4 +1,4 @@
-<?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;
     }
 }
diff --git a/tests/FileLocator/FileLocatorTest.php b/tests/FileLocator/FileLocatorTest.php
index 7dc2e35..c401cda 100644
--- a/tests/FileLocator/FileLocatorTest.php
+++ b/tests/FileLocator/FileLocatorTest.php
@@ -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());
diff --git a/tests/HeaderComment/LicenseTemplateProviderTest.php b/tests/HeaderComment/LicenseTemplateProviderTest.php
index a84096b..0fdcb1f 100644
--- a/tests/HeaderComment/LicenseTemplateProviderTest.php
+++ b/tests/HeaderComment/LicenseTemplateProviderTest.php
@@ -1,4 +1,4 @@
-<?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()
-- 
GitLab