Skip to content

Commit

Permalink
Fix multiple type and contravariance issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ralflang committed Oct 30, 2023
1 parent 67dd5c2 commit 96af4cb
Show file tree
Hide file tree
Showing 51 changed files with 133 additions and 99 deletions.
4 changes: 2 additions & 2 deletions src/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function getLicenseLocation(): string;
/**
* Indicate if the component has a local package.xml.
*
* @return boolean True if a package.xml exists.
* @return bool True if a package.xml exists.
*/
public function hasLocalPackageXml(): bool;

Expand Down Expand Up @@ -239,7 +239,7 @@ public function tag(string $tag, string $message, HelperCommit $commit): string;
* archive, optionally [1] an array of error strings, and [2]
* PEAR output.
*/
public function placeArchive($destination, $options = []): array;
public function placeArchive(string $destination, $options = []): array;

/**
* Identify the repository root.
Expand Down
11 changes: 7 additions & 4 deletions src/Component/Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use Horde\Components\Config;
use Horde\Components\Exception;
use Horde\Components\Pear\Environment as PearEnvironment;
use Horde\Components\Wrapper\PackageXml;
use Horde_Pear_Package_Xml;

/**
* Represents a component archive.
Expand All @@ -33,6 +35,7 @@
*/
class Archive extends Base
{
protected Horde_Pear_Package_Xml|null $package = null;
/**
* Constructor.
*
Expand Down Expand Up @@ -106,14 +109,14 @@ public function install(
*
* @return \Horde_Pear_Package_Xml The package representation.
*/
protected function getPackageXml()
protected function getPackageXml(): PackageXml
{
if (!isset($this->_package)) {
$this->_package = $this->getFactory()->createPackageXml(
if (!isset($this->package)) {
$this->package = $this->getFactory()->createPackageXml(
$this->_loadPackageFromArchive()
);
}
return $this->_package;
return $this->package;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Component/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public function getNotes()
/**
* Indicate if the component has a local package.xml.
*
* @return boolean True if a package.xml exists.
* @return bool True if a package.xml exists.
*/
public function hasLocalPackageXml(): bool
{
Expand Down Expand Up @@ -479,7 +479,7 @@ protected function getBaseInstallationOptions($options)
/**
* Check if the library has a CI job.
*
* @return boolean True if a CI job is defined.
* @return bool True if a CI job is defined.
* @throws Exception
*/
protected function _hasCi()
Expand Down
14 changes: 7 additions & 7 deletions src/Component/DependencyList.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,18 @@ public function __get($key): Dependency|null
if (isset($dependencies[$key])) {
return $dependencies[$key];
}
return null;
}

/**
* Implementation of the Iterator rewind() method. Rewinds the dependency list.
*
* @return Dependency|null
* @return void
*/
public function rewind(): Dependency|null
public function rewind(): void
{
$this->_getDependencies();
return reset($this->_dependencies);
reset($this->_dependencies);
}

/**
Expand All @@ -144,22 +145,21 @@ public function key(): Dependency|null
/**
* Implementation of the Iterator next() method. Returns the next dependency.
*
* @return Dependency|null The next
* @return void The next
* dependency or null if there are no more dependencies.
*/
public function next(): Dependency|null
public function next(): void
{
$res = next($this->_dependencies);
if ($res === false) {
return null;
}
return $res;
}

/**
* Implementation of the Iterator valid() method. Indicates if the current element is a valid element.
*
* @return boolean Whether the current element is valid
* @return bool Whether the current element is valid
*/
public function valid(): bool
{
Expand Down
10 changes: 5 additions & 5 deletions src/Component/Identify.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private function _determineComponent($arguments)
*
* @param string $path The path to the directory.
*
* @return boolean True if it is a directory
* @return bool True if it is a directory
*/
private function _isDirectory($path)
{
Expand All @@ -182,7 +182,7 @@ private function _isDirectory($path)
*
* @param string $path The path to the directory.
*
* @return boolean True if the directory contains a package.xml file.
* @return bool True if the directory contains a package.xml file.
*/
private function _containsPackageXml($path)
{
Expand All @@ -194,7 +194,7 @@ private function _containsPackageXml($path)
*
* @param string $path The path.
*
* @return boolean True if the provided file name points to a package.xml
* @return bool True if the provided file name points to a package.xml
* file.
*/
private function _isPackageXml($path)
Expand All @@ -210,7 +210,7 @@ private function _isPackageXml($path)
*
* @param string $path The path.
*
* @return boolean True if the provided file name points to a .horde.yml
* @return bool True if the provided file name points to a .horde.yml
* file.
*/
private function _isHordeYml($path)
Expand All @@ -226,7 +226,7 @@ private function _isHordeYml($path)
*
* @param string $path The path to the directory.
*
* @return boolean True if the directory contains the file.
* @return bool True if the directory contains the file.
*/
private function _containsHordeYml($path)
{
Expand Down
17 changes: 10 additions & 7 deletions src/Component/Remote.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

use Horde\Components\Config;
use Horde\Components\Exception;
use stdClass;
use Horde\Components\Pear\Environment as PearEnvironment;
use Horde\Components\Wrapper\PackageXml;

/**
* Represents a remote component.
Expand Down Expand Up @@ -151,9 +154,9 @@ public function getDependencies(): array
* Return a data array with the most relevant information about this
* component.
*
* @return array Information about this component.
* @return stdClass Information about this component.
*/
public function getData()
public function getData(): stdClass
{
$data = new \stdClass();
$release = $this->_remote->getLatestDetails($this->_name, null);
Expand All @@ -177,7 +180,7 @@ public function getData()
* archive, optionally [1] an array of error strings, and [2]
* PEAR output.
*/
public function placeArchive($destination, $options = []): array
public function placeArchive(string $destination, $options = []): array
{
$this->createDestination($destination);
$this->_client->{'request.timeout'} = 60;
Expand Down Expand Up @@ -207,14 +210,14 @@ private function _getDownloadUri(): string
/**
* Install a component.
*
* @param Components_Pear_Environment $env The environment to install
* @param PearEnvironment $env The environment to install
* into.
* @param array $options Install options.
* @param string $reason Optional reason for adding the
* package.
*/
public function install(
Components_Pear_Environment $env,
PearEnvironment $env,
$options = [],
$reason = ''
): void {
Expand Down Expand Up @@ -248,9 +251,9 @@ public function install(
/**
* Return a PEAR package representation for the component.
*
* @return \Horde_Pear_Package_Xml The package representation.
* @return PackageXml The package representation.
*/
protected function getPackageXml()
protected function getPackageXml(): PackageXml
{
if (!isset($this->_package)) {
$this->_package = $this->_remote->getPackageXml(
Expand Down
4 changes: 2 additions & 2 deletions src/Component/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public function getData(): stdClass
/**
* Indicate if the component has a local package.xml.
*
* @return boolean True if a package.xml exists.
* @return bool True if a package.xml exists.
* @throws Exception
*/
public function hasLocalPackageXml(): bool
Expand Down Expand Up @@ -1034,7 +1034,7 @@ public function tag($tag, $message, $commit): string
* PEAR output.
* @throws Exception
*/
public function placeArchive($destination, $options = []): array
public function placeArchive(string $destination, $options = []): array
{
if (!$this->getPackageXml()->exists()) {
throw new Exception(
Expand Down
1 change: 1 addition & 0 deletions src/Component/Task/SystemCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ protected function system($call)
} else {
$this->getOutput()->info(sprintf('Would run "%s" now.', $call));
}
return '';
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Configs.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ public function unshiftConfigurationType(Config $type): void
/**
* Provide each configuration handler with the list of supported modules.
*
* @param Modules $modules A list of modules.
* @param Module[] $modules A list of modules.
*/
public function handleModules(Modules $modules): void
public function handleModules(array|iterable $modules): void
{
foreach ($this->_configs as $config) {
$config->handleModules($modules);
Expand Down
2 changes: 1 addition & 1 deletion src/Dependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Horde\Components\Runner\CiSetup as RunnerCiSetup;
use Horde\Components\Runner\Composer as RunnerComposer;
use Horde\Components\Runner\Distribute as RunnerDistribute;
use Horde\Components\Runner\FetchDocs as RunnerFetchDocs;
use Horde\Components\Runner\Fetchdocs as RunnerFetchDocs;
use Horde\Components\Runner\Installer as RunnerInstaller;
use Horde\Components\Runner\Qc as RunnerQc;
use Horde\Components\Runner\Release as RunnerRelease;
Expand Down
2 changes: 1 addition & 1 deletion src/Dependencies/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
use Horde\Components\Runner\Release as RunnerRelease;
use Horde\Components\Runner\Snapshot as RunnerSnapshot;
use Horde\Components\Runner\Update as RunnerUpdate;
use Horde\Components\Runner\WebDocs as RunnerWebDocs;
use Horde\Components\Runner\Webdocs as RunnerWebDocs;

/**
* The Components_Dependencies_Bootstrap:: class provides the Components
Expand Down
2 changes: 1 addition & 1 deletion src/Dependencies/Injector.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
use Horde\Components\Runner\Release as RunnerRelease;
use Horde\Components\Runner\Snapshot as RunnerSnapshot;
use Horde\Components\Runner\Update as RunnerUpdate;
use Horde\Components\Runner\WebDocs as RunnerWebDocs;
use Horde\Components\Runner\Webdocs as RunnerWebdocs;
use Horde\Injector\Injector as HordeInjector;
use Horde\Injector\TopLevel;

Expand Down
8 changes: 5 additions & 3 deletions src/Helper/ChangeLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ public function __construct(Config $config, protected Component $_component)
*
* @return string Path to the updated changelog.yml file.
*/
public function changelogYml($log, $options)
public function changelogYml($log, $options): string
{
if (!strlen($log)) {
return;
return '';
}

if ($changelog = $this->changelogFileExists()) {
Expand All @@ -70,6 +70,7 @@ public function changelogYml($log, $options)
}
return $changelog;
}
return '';
}

/**
Expand Down Expand Up @@ -262,12 +263,13 @@ public function migrateToChangelogYml($xml): void
*
* @return string Path to the updated package.xml file.
*/
public function packageXml($log, $xml)
public function packageXml($log, $xml): string
{
if ($xml->exists()) {
$xml->addNote($log);
return $xml->getFullPath();
}
return '';
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/Helper/Commit.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Commit
/**
* Modified paths.
*/
private array $_added = [];
private array $added = [];

/**
* Constructor.
Expand Down Expand Up @@ -64,7 +64,7 @@ public function add($path, $directory): void
if ($path instanceof Wrapper) {
$path = $path->getLocalPath($directory);
}
$this->_added[$path] = $directory;
$this->added[$path] = $directory;
}

/**
Expand All @@ -74,14 +74,14 @@ public function add($path, $directory): void
*/
public function commit($log): void
{
if (empty($this->_added)) {
if (empty($this->added)) {
return;
}
foreach ($this->_added as $path => $wd) {
foreach ($this->added as $path => $wd) {
$this->systemInDirectory('git add ' . $path, $wd);
}
$this->systemInDirectory('git commit -m "' . $log . '"', $wd);
$this->_added = [];
$this->added = [];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Helper/Dependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private function _listTree(
* @param string $parent Name of the parent element.
* @param array $options Options for generating the list.
*
* @return boolean True in case listing should continue.
* @return bool True in case listing should continue.
*/
private function _listComponent(
Component $component,
Expand Down
Loading

0 comments on commit 96af4cb

Please sign in to comment.