Skip to content

Commit

Permalink
Merge pull request #351 from oat-sa/feat/TR-4876/add-return-types
Browse files Browse the repository at this point in the history
Feat/tr 4876/add return types
  • Loading branch information
kilatib authored Dec 23, 2022
2 parents 360798c + 6c2615a commit f86e4dc
Show file tree
Hide file tree
Showing 1,451 changed files with 7,786 additions and 7,719 deletions.
17 changes: 4 additions & 13 deletions .github/workflows/continuous-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,23 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.head_ref || github.ref_name }}

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}

- name: Check PHP Version
run: php -v

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run test suite
run: php -dxdebug.mode=coverage vendor/bin/phpunit --coverage-clover coverage.xml

- name: Push coverage report
run: bash <(curl -s https://codecov.io/bash)
uses: codecov/codecov-action@v2
26 changes: 13 additions & 13 deletions src/qtism/cli/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ abstract class Cli
*
* @var int
*/
const EXIT_SUCCESS = 0;
public const EXIT_SUCCESS = 0;

/**
* POSIX generic exit status (1).
Expand All @@ -69,7 +69,7 @@ abstract class Cli
*
* @var int
*/
const EXIT_FAILURE = 1;
public const EXIT_FAILURE = 1;

/**
* An Arguments object (from php-cli-tools) representing the input
Expand All @@ -83,7 +83,7 @@ abstract class Cli
/**
* Main CLI entry point.
*/
public static function main()
public static function main(): void
{
$cli = new static();

Expand Down Expand Up @@ -122,7 +122,7 @@ abstract protected function run();
* @return Arguments An Arguments object (from php-cli-tools).
* @see https://github.com/wp-cli/php-cli-tools The PHP CLI Tools github repository.
*/
abstract protected function setupArguments();
abstract protected function setupArguments(): Arguments;

/**
* Check the arguments given to the CLI Module.
Expand All @@ -141,7 +141,7 @@ abstract protected function checkArguments();
*
* @param Arguments $arguments An Arguments object from php-cli-tools.
*/
private function setArguments(Arguments $arguments)
private function setArguments(Arguments $arguments): void
{
$this->arguments = $arguments;
}
Expand All @@ -151,7 +151,7 @@ private function setArguments(Arguments $arguments)
*
* @return Arguments An Arguments object from php-cli-tools.
*/
protected function getArguments()
protected function getArguments(): Arguments
{
return $this->arguments;
}
Expand All @@ -163,7 +163,7 @@ protected function getArguments()
*
* @param string $message The error message.
*/
protected function error($message)
protected function error($message): void
{
$this->out("%r${message}%n", true);
}
Expand All @@ -176,7 +176,7 @@ protected function error($message)
*
* @param string $message The success message.
*/
protected function success($message)
protected function success($message): void
{
if ($this->isVerbose() === true) {
$this->out("%g${message}%n", true);
Expand All @@ -192,7 +192,7 @@ protected function success($message)
*
* @param string $message The error message.
*/
protected function fail($message)
protected function fail($message): void
{
$this->error($message);
exit(self::EXIT_FAILURE);
Expand All @@ -201,7 +201,7 @@ protected function fail($message)
/**
* @param $longName
*/
protected function missingArgument($longName)
protected function missingArgument($longName): void
{
$arguments = $this->getArguments();
$options = $arguments->getOptions();
Expand All @@ -225,7 +225,7 @@ protected function missingArgument($longName)
*
* @param string $message An information message.
*/
protected function info($message)
protected function info($message): void
{
if ($this->isVerbose() === true) {
$this->out("%w${message}%n", true);
Expand All @@ -238,7 +238,7 @@ protected function info($message)
* @param string $data The data to go in output.
* @param bool $newLine Whether to display a new line after $data.
*/
protected function out($data, $newLine = true)
protected function out($data, $newLine = true): void
{
CliTools\out($data);

Expand All @@ -255,7 +255,7 @@ protected function out($data, $newLine = true)
*
* @return bool
*/
protected function isVerbose()
protected function isVerbose(): bool
{
$arguments = $this->getArguments();
return $this->arguments['verbose'] === true;
Expand Down
12 changes: 6 additions & 6 deletions src/qtism/cli/Render.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Render extends Cli
/**
* @return Arguments
*/
protected function setupArguments()
protected function setupArguments(): Arguments
{
$arguments = new Arguments(['strict' => false]);

Expand Down Expand Up @@ -104,7 +104,7 @@ protected function setupArguments()
return $arguments;
}

protected function checkArguments()
protected function checkArguments(): void
{
$arguments = $this->getArguments();

Expand Down Expand Up @@ -159,7 +159,7 @@ protected function checkArguments()
* This implementations considers that all necessary checks about
* arguments and their values were performed in \qtism\cli\Render::checkArguments().
*/
protected function run()
protected function run(): void
{
$engine = $this->instantiateEngine();
$arguments = $this->getArguments();
Expand Down Expand Up @@ -227,7 +227,7 @@ protected function run()
* @return string The rendered data as a string.
* @throws RenderingException
*/
private function runGoldilocks(XmlDocument $doc, GoldilocksRenderingEngine $renderer)
private function runGoldilocks(XmlDocument $doc, GoldilocksRenderingEngine $renderer): string
{
$arguments = $this->getArguments();
$profile = $arguments['flavour'];
Expand Down Expand Up @@ -315,7 +315,7 @@ private function runGoldilocks(XmlDocument $doc, GoldilocksRenderingEngine $rend
* @return string The raw rendering data.
* @throws RenderingException
*/
private function runXhtml(XmlDocument $doc, XhtmlRenderingEngine $renderer)
private function runXhtml(XmlDocument $doc, XhtmlRenderingEngine $renderer): string
{
$arguments = $this->getArguments();
$profile = $arguments['flavour'];
Expand Down Expand Up @@ -385,7 +385,7 @@ private function runXhtml(XmlDocument $doc, XhtmlRenderingEngine $renderer)
*
* @return AbstractMarkupRenderingEngine
*/
private function instantiateEngine()
private function instantiateEngine(): AbstractMarkupRenderingEngine
{
$arguments = $this->getArguments();
$engine = null;
Expand Down
2 changes: 1 addition & 1 deletion src/qtism/common/Comparable.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ interface Comparable
* @return bool Whether the object to compare is equal to this one.
* @link http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#equals(java.lang.Object)
*/
public function equals($obj);
public function equals($obj): bool;
}
2 changes: 0 additions & 2 deletions src/qtism/common/QtiSdkPackageContentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
*
* @license GPLv2
*/
declare(strict_types=1);

namespace qtism\common;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/qtism/common/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ interface Resolver
* @return string A resolved URL.
* @throws ResolutionException If an error occurs during the resolution of $url.
*/
public function resolve($url);
public function resolve($url): string;
}
36 changes: 18 additions & 18 deletions src/qtism/common/beans/Bean.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Bean
*
* @var string
*/
const ANNOTATION_PROPERTY = '@qtism-bean-property';
public const ANNOTATION_PROPERTY = '@qtism-bean-property';

/**
* The object to be wrapped as a bean as a PHP ReflectionObject.
Expand Down Expand Up @@ -85,7 +85,7 @@ public function __construct($object, $strict = false, $asInstanceOf = '')
*
* @param ReflectionClass $class A ReflectionClass object.
*/
protected function setClass(ReflectionClass $class)
protected function setClass(ReflectionClass $class): void
{
$this->class = $class;
}
Expand All @@ -95,7 +95,7 @@ protected function setClass(ReflectionClass $class)
*
* @return ReflectionClass A ReflectionClass object.
*/
protected function getClass()
protected function getClass(): ReflectionClass
{
return $this->class;
}
Expand All @@ -109,7 +109,7 @@ protected function getClass()
* @throws InvalidArgumentException If $property is not a string nor a Bean
* @throws ReflectionException
*/
public function getGetter($property)
public function getGetter($property): BeanMethod
{
if (is_string($property)) {
$propertyName = $property;
Expand Down Expand Up @@ -178,7 +178,7 @@ public function hasGetter($property)
* @throws BeanException
* @throws ReflectionException
*/
public function getGetters($excludeConstructor = false)
public function getGetters($excludeConstructor = false): BeanMethodCollection
{
$methods = new BeanMethodCollection();

Expand All @@ -202,7 +202,7 @@ public function getGetters($excludeConstructor = false)
* @throws InvalidArgumentException If $property is not a string nor a BeanProperty object.
* @throws ReflectionException
*/
public function getSetter($property)
public function getSetter($property): BeanMethod
{
if (is_string($property)) {
$propertyName = $property;
Expand Down Expand Up @@ -238,7 +238,7 @@ public function getSetter($property)
* @return bool
* @throws ReflectionException
*/
public function hasSetter($property)
public function hasSetter($property): bool
{
if (is_string($property)) {
$propertyName = $property;
Expand Down Expand Up @@ -267,7 +267,7 @@ public function hasSetter($property)
* @throws BeanException
* @throws ReflectionException
*/
public function getSetters($excludeConstructor = false)
public function getSetters($excludeConstructor = false): BeanMethodCollection
{
$methods = new BeanMethodCollection();

Expand All @@ -293,7 +293,7 @@ public function getSetters($excludeConstructor = false)
* @return bool
* @throws ReflectionException
*/
public function hasProperty($propertyName)
public function hasProperty($propertyName): bool
{
return $this->isPropertyAnnotated($propertyName);
}
Expand All @@ -306,7 +306,7 @@ public function hasProperty($propertyName)
* @throws BeanException
* @throws ReflectionException
*/
public function getProperty($propertyName)
public function getProperty($propertyName): BeanProperty
{
$className = $this->getClass()->getName();

Expand All @@ -330,7 +330,7 @@ public function getProperty($propertyName)
* @throws BeanException
* @throws ReflectionException
*/
public function getProperties()
public function getProperties(): BeanPropertyCollection
{
$properties = new BeanPropertyCollection();

Expand Down Expand Up @@ -361,7 +361,7 @@ public function getProperties()
* @throws BeanException
* @throws ReflectionException
*/
public function getConstructorGetters()
public function getConstructorGetters(): BeanMethodCollection
{
$getters = new BeanMethodCollection();

Expand All @@ -379,7 +379,7 @@ public function getConstructorGetters()
* @throws BeanException
* @throws ReflectionException
*/
public function getConstructorSetters()
public function getConstructorSetters(): BeanMethodCollection
{
$setters = new BeanMethodCollection();

Expand All @@ -398,7 +398,7 @@ public function getConstructorSetters()
* @throws BeanException
* @throws ReflectionException
*/
public function getConstructorParameters()
public function getConstructorParameters(): BeanParameterCollection
{
$parameters = new BeanParameterCollection();

Expand All @@ -421,7 +421,7 @@ public function getConstructorParameters()
* @return bool
* @throws ReflectionException
*/
public function hasConstructorParameter($parameterName)
public function hasConstructorParameter($parameterName): bool
{
$hasConstructorParameter = false;

Expand All @@ -444,7 +444,7 @@ public function hasConstructorParameter($parameterName)
* @return bool
* @throws ReflectionException
*/
protected function isPropertyAnnotated($propertyName)
protected function isPropertyAnnotated($propertyName): bool
{
$target = $this->getClass();
$isAnnotated = false;
Expand Down Expand Up @@ -474,7 +474,7 @@ protected function isPropertyAnnotated($propertyName)
* @throws BeanException
* @throws ReflectionException
*/
protected function validateStrictBean()
protected function validateStrictBean(): void
{
/*
* 1st rule to respect:
Expand Down Expand Up @@ -532,7 +532,7 @@ protected function validateStrictBean()
* @param string $propertyName The name of the property.
* @return array An array of possible getter method names for a given $propertyName.
*/
protected static function getPossibleGetterNames($propertyName)
protected static function getPossibleGetterNames($propertyName): array
{
$ucPropName = ucfirst($propertyName);

Expand Down
Loading

0 comments on commit f86e4dc

Please sign in to comment.