Skip to content

Commit

Permalink
Migrated codebase to php 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
stevleibelt committed Nov 23, 2022
1 parent a38f5ce commit 4ae413e
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 187 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea
composer.lock
vendor
.phpunit.result.cache
phpunit.xml.dist.bak
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Changeed

## [2.1.0](https://github.com/bazzline/php_component_cli_argument/tree/2.1.0) - released at 2022-11-23

### Changeed

* Raised minimum php version requirement from `7.0` to `8.0`
* Updated development requirement from phpunit 6.0 to 8.0
* Migrated phpunit xml
* Migrated code base to php 8.0

## [2.0.0](https://github.com/bazzline/php_component_cli_argument/tree/2.0.0) - released at 2018-01-12

### Changed
Expand Down
4 changes: 3 additions & 1 deletion Example/run.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
* @since: 2015-04-16
*/

use Net\Bazzline\Component\Cli\Arguments\Arguments;

require_once __DIR__ . '/../vendor/autoload.php';

$arguments = new \Net\Bazzline\Component\Cli\Arguments\Arguments($argv);
$arguments = new Arguments($argv);

if ($arguments->hasArguments()) {
echo $arguments->getNumberOfArguments() . ' arguments provided:' . PHP_EOL;
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"type": "library",
"minimum-stability": "dev",
"require": {
"php": "~7.0"
"php": "~8.0"
},
"require-dev": {
"phpunit/phpunit": "~6.0"
"phpunit/phpunit": "~9.0"
},
"license": "LGPL-3.0-only",
"authors": [
Expand Down
24 changes: 8 additions & 16 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
<phpunit bootstrap="test/bootstrap.php"
cacheTokens="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false">

<testsuites>
<testsuite name="Test Suite">
<directory>test/</directory>
</testsuite>
</testsuites>
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="test/bootstrap.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage/>
<testsuites>
<testsuite name="Test Suite">
<directory>test/</directory>
</testsuite>
</testsuites>
</phpunit>
130 changes: 26 additions & 104 deletions source/Arguments.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,13 @@

class Arguments
{
/** @var array */
private $arguments;
private array $arguments;
private array $flags;
private array $lists;
private Parser $parser;
private array $values;

/** @var array */
private $flags;

/** @var array */
private $lists;

/** @var Parser */
private $parser;

/** @var array */
private $values;

/**
* @param null|array $argv
* @param boolean $removeFirstArgument
*/
public function __construct($argv = null, $removeFirstArgument = true)
public function __construct(array $argv = null, bool $removeFirstArgument = true)
{
$this->parser = new Parser();

Expand All @@ -38,137 +25,84 @@ public function __construct($argv = null, $removeFirstArgument = true)
}
}

/**
* @return array
*/
public function getArguments()
public function getArguments(): array
{
return $this->arguments;
}

/**
* @return array
*/
public function getFlags()
public function getFlags(): array
{
return $this->flags;
}

/**
* @param string $name
* @return null|array
*/
public function getList($name)
public function getList(string $name): null|array
{
return (isset($this->lists[$name]))
? $this->lists[$name]
: null;
}

/**
* @return int
*/
public function getNumberOfArguments()
public function getNumberOfArguments(): int
{
return (count($this->arguments));
}

/**
* @return int
*/
public function getNumberOfFlags()
public function getNumberOfFlags(): int
{
return (count($this->flags));
}

/**
* @return int
*/
public function getNumberOfLists()
public function getNumberOfLists(): int
{
return (count($this->lists));
}

/**
* @return int
*/
public function getNumberOfValues()
public function getNumberOfValues(): int
{
return (count($this->values));
}

/**
* @return array
*/
public function getLists()
public function getLists(): array
{
return $this->lists;
}

/**
* @return array
*/
public function getValues()
public function getValues(): array
{
return $this->values;
}

/**
* @return bool
*/
public function hasArguments()
public function hasArguments(): bool
{
return (!empty($this->arguments));
}

/**
* @param string $name
* @return bool
*/
public function hasFlag($name)
public function hasFlag(string $name): bool
{
return (in_array($name, $this->flags));
}

/**
* @return bool
*/
public function hasFlags()
public function hasFlags(): bool
{
return (!empty($this->flags));
}

/**
* @param string $name
* @return bool
*/
public function hasList($name)
public function hasList(string $name): bool
{
return (isset($this->lists[$name]));
}

/**
* @return bool
*/
public function hasLists()
public function hasLists(): bool
{
return (!empty($this->lists));
}

/**
* @return bool
*/
public function hasValues()
public function hasValues(): bool
{
return (!empty($this->values));
}

/**
* @param array $argv
* @param boolean $removeFirstArgument
* @return $this
*/
public function parseArguments(array $argv, $removeFirstArgument = true)
public function parseArguments(array $argv, bool $removeFirstArgument = true): self
{
if ($removeFirstArgument) {
array_shift($argv);
Expand All @@ -181,34 +115,22 @@ public function parseArguments(array $argv, $removeFirstArgument = true)
return $this;
}

/**
* @return array
*/
public function convertToArray()
public function convertToArray(): array
{
return $this->getArguments();
}

/**
* @return string
*/
public function convertToString()
public function convertToString(): string
{
return implode(' ', $this->convertToArray());
}

/**
* @return string
*/
public function __toString()
public function __toString(): string
{
return $this->convertToString();
}

/**
* @param Parser $parser
*/
private function setArgumentsFromParser(Parser $parser)
private function setArgumentsFromParser(Parser $parser): void
{
$this->flags = $parser->getFlags();
$this->lists = $parser->getLists();
Expand Down
Loading

0 comments on commit 4ae413e

Please sign in to comment.