From d245e8d184a3ca9225549277fbaf11150fba48b2 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 27 Sep 2022 18:08:15 +0200 Subject: [PATCH] fixing phpstan errors --- Ai/NeuralNetwork/Neuron.php | 12 +++++++++++- Contract/RenderableInterface.php | 2 +- .../Database/Mapper/DataMapperAbstract.php | 2 +- DataStorage/Database/Mapper/DeleteMapper.php | 2 +- DataStorage/Database/Mapper/ReadMapper.php | 4 ++-- DataStorage/Database/Mapper/UpdateMapper.php | 2 +- DataStorage/Database/Mapper/WriteMapper.php | 2 +- DataStorage/Database/Query/Builder.php | 16 ++++++++-------- Dispatcher/Dispatcher.php | 2 +- Dispatcher/DispatcherInterface.php | 4 ++-- Event/EventManager.php | 2 +- Math/Geometry/Shape/D2/Triangle.php | 2 +- Message/Console/ConsoleResponse.php | 2 +- Message/Http/HttpResponse.php | 2 +- Message/Socket/SocketResponse.php | 2 +- Model/Html/Head.php | 2 +- Model/Html/Meta.php | 2 +- Views/ViewAbstract.php | 16 +++++++++++++--- tests/Message/Http/HttpResponseTest.php | 4 ++-- tests/Utils/StringUtilsTest.php | 2 +- tests/phpunit_no_coverage.xml | 1 + 21 files changed, 53 insertions(+), 32 deletions(-) diff --git a/Ai/NeuralNetwork/Neuron.php b/Ai/NeuralNetwork/Neuron.php index 4dba657c5..66e7c3022 100644 --- a/Ai/NeuralNetwork/Neuron.php +++ b/Ai/NeuralNetwork/Neuron.php @@ -64,7 +64,17 @@ class Neuron $this->bias = $bias; } - public function addInput($input, float $weight) : void + /** + * Add neuron input + * + * @param mixed $input Input + * @param float $weight Weight of input + * + * @return void + * + * @since 1.0.0 + */ + public function addInput(mixed $input, float $weight) : void { $this->inputs[] = $input; $this->weights[] = $weight; diff --git a/Contract/RenderableInterface.php b/Contract/RenderableInterface.php index 1adaf72fd..5ef7d1364 100755 --- a/Contract/RenderableInterface.php +++ b/Contract/RenderableInterface.php @@ -36,5 +36,5 @@ interface RenderableInterface * * @since 1.0.0 */ - public function render(...$data) : string; + public function render(mixed ...$data) : string; } diff --git a/DataStorage/Database/Mapper/DataMapperAbstract.php b/DataStorage/Database/Mapper/DataMapperAbstract.php index 9aede4b9a..6f0ba0a2d 100644 --- a/DataStorage/Database/Mapper/DataMapperAbstract.php +++ b/DataStorage/Database/Mapper/DataMapperAbstract.php @@ -422,5 +422,5 @@ abstract class DataMapperAbstract * * @since 1.0.0 */ - abstract public function execute(...$options) : mixed; + abstract public function execute(mixed ...$options) : mixed; } diff --git a/DataStorage/Database/Mapper/DeleteMapper.php b/DataStorage/Database/Mapper/DeleteMapper.php index 6e92f64ba..0f322f17e 100644 --- a/DataStorage/Database/Mapper/DeleteMapper.php +++ b/DataStorage/Database/Mapper/DeleteMapper.php @@ -49,7 +49,7 @@ final class DeleteMapper extends DataMapperAbstract * * @since 1.0.0 */ - public function execute(...$options) : mixed + public function execute(mixed ...$options) : mixed { switch($this->type) { case MapperType::DELETE: diff --git a/DataStorage/Database/Mapper/ReadMapper.php b/DataStorage/Database/Mapper/ReadMapper.php index e411ea5c3..a421cad37 100644 --- a/DataStorage/Database/Mapper/ReadMapper.php +++ b/DataStorage/Database/Mapper/ReadMapper.php @@ -136,7 +136,7 @@ final class ReadMapper extends DataMapperAbstract * * @since 1.0.0 */ - public function execute(...$options) : mixed + public function execute(mixed ...$options) : mixed { switch($this->type) { case MapperType::GET: @@ -577,7 +577,7 @@ final class ReadMapper extends DataMapperAbstract $refProp->setValue($obj, $value); } elseif (\in_array($def['type'], ['string', 'compress', 'int', 'float', 'bool'])) { if ($value !== null && $def['type'] === 'compress') { - $def['type'] = 'string'; + $def['type'] = 'string'; $value = \gzinflate($value); } diff --git a/DataStorage/Database/Mapper/UpdateMapper.php b/DataStorage/Database/Mapper/UpdateMapper.php index 7e13ec9c5..d5bf2f40e 100644 --- a/DataStorage/Database/Mapper/UpdateMapper.php +++ b/DataStorage/Database/Mapper/UpdateMapper.php @@ -51,7 +51,7 @@ final class UpdateMapper extends DataMapperAbstract * * @since 1.0.0 */ - public function execute(...$options) : mixed + public function execute(mixed ...$options) : mixed { switch($this->type) { case MapperType::UPDATE: diff --git a/DataStorage/Database/Mapper/WriteMapper.php b/DataStorage/Database/Mapper/WriteMapper.php index 3d594c181..b4f60fa01 100644 --- a/DataStorage/Database/Mapper/WriteMapper.php +++ b/DataStorage/Database/Mapper/WriteMapper.php @@ -52,7 +52,7 @@ final class WriteMapper extends DataMapperAbstract * * @since 1.0.0 */ - public function execute(...$options) : mixed + public function execute(mixed ...$options) : mixed { switch($this->type) { case MapperType::CREATE: diff --git a/DataStorage/Database/Query/Builder.php b/DataStorage/Database/Query/Builder.php index 0de9285b1..3c267fd22 100644 --- a/DataStorage/Database/Query/Builder.php +++ b/DataStorage/Database/Query/Builder.php @@ -279,7 +279,7 @@ class Builder extends BuilderAbstract * * @since 1.0.0 */ - public function select(...$columns) : self + public function select(mixed ...$columns) : self { $this->type = QueryType::SELECT; @@ -323,7 +323,7 @@ class Builder extends BuilderAbstract * * @since 1.0.0 */ - public function random(...$columns) : self + public function random(mixed ...$columns) : self { $this->select(...$columns); @@ -498,7 +498,7 @@ class Builder extends BuilderAbstract * * @since 1.0.0 */ - public function from(...$tables) : self + public function from(mixed ...$tables) : self { /** @var mixed[] $tables */ /** @var mixed $table */ @@ -665,7 +665,7 @@ class Builder extends BuilderAbstract * * @since 1.0.0 */ - public function groupBy(...$columns) : self + public function groupBy(mixed ...$columns) : self { /** @var mixed[] $columns */ /** @var mixed $column */ @@ -908,7 +908,7 @@ class Builder extends BuilderAbstract * * @since 1.0.0 */ - public function insert(...$columns) : self + public function insert(mixed ...$columns) : self { if ($this->isReadOnly) { throw new \Exception(); @@ -948,7 +948,7 @@ class Builder extends BuilderAbstract * * @since 1.0.0 */ - public function values(...$values) : self + public function values(mixed ...$values) : self { $this->values[] = $values; @@ -1003,7 +1003,7 @@ class Builder extends BuilderAbstract * * @since 1.0.0 */ - public function sets(...$sets) : self + public function sets(mixed ...$sets) : self { $this->sets[$sets[0]] = $sets[1] ?? null; @@ -1037,7 +1037,7 @@ class Builder extends BuilderAbstract * * @since 1.0.0 */ - public function update(...$tables) : self + public function update(mixed ...$tables) : self { if ($this->isReadOnly) { throw new \Exception(); diff --git a/Dispatcher/Dispatcher.php b/Dispatcher/Dispatcher.php index b9c2f04d1..caaa1b712 100644 --- a/Dispatcher/Dispatcher.php +++ b/Dispatcher/Dispatcher.php @@ -62,7 +62,7 @@ final class Dispatcher implements DispatcherInterface /** * {@inheritdoc} */ - public function dispatch(array | string | \Closure $controller, ...$data) : array + public function dispatch(array | string | \Closure $controller, mixed ...$data) : array { $views = []; $data = \array_values($data); diff --git a/Dispatcher/DispatcherInterface.php b/Dispatcher/DispatcherInterface.php index 3e4409eb7..a3635c713 100755 --- a/Dispatcher/DispatcherInterface.php +++ b/Dispatcher/DispatcherInterface.php @@ -28,7 +28,7 @@ interface DispatcherInterface * Dispatch controller. * * @param array|\Closure|string $controller Controller - * @param null|array|mixed ...$data Data + * @param mixed ...$data Data * * @return array Returns array of all dispatched results * @@ -36,5 +36,5 @@ interface DispatcherInterface * * @since 1.0.0 */ - public function dispatch(array | string | \Closure $controller, ...$data) : array; + public function dispatch(array | string | \Closure $controller, mixed ...$data) : array; } diff --git a/Event/EventManager.php b/Event/EventManager.php index a0dd75463..306168f01 100644 --- a/Event/EventManager.php +++ b/Event/EventManager.php @@ -70,7 +70,7 @@ final class EventManager implements \Countable /** * {@inheritdoc} */ - public function dispatch(array | string | \Closure $func, ...$data) : array + public function dispatch(array | string | \Closure $func, mixed ...$data) : array { if (!($func instanceof \Closure)) { return []; diff --git a/Math/Geometry/Shape/D2/Triangle.php b/Math/Geometry/Shape/D2/Triangle.php index 19982af12..ebd36f6f9 100644 --- a/Math/Geometry/Shape/D2/Triangle.php +++ b/Math/Geometry/Shape/D2/Triangle.php @@ -85,7 +85,7 @@ final class Triangle implements D2ShapeInterface * * @since 1.0.0 */ - public static function getHypot(...$vec) : float + public static function getHypot(mixed ...$vec) : float { $hypot = 0.0; foreach ($vec as $val) { diff --git a/Message/Console/ConsoleResponse.php b/Message/Console/ConsoleResponse.php index 8412f80e0..bac69d2c4 100644 --- a/Message/Console/ConsoleResponse.php +++ b/Message/Console/ConsoleResponse.php @@ -105,7 +105,7 @@ final class ConsoleResponse extends ResponseAbstract implements RenderableInterf * * @since 1.0.0 */ - public function render(...$data) : string + public function render(mixed ...$data) : string { $types = $this->header->get('Content-Type'); diff --git a/Message/Http/HttpResponse.php b/Message/Http/HttpResponse.php index c0fd750cd..a2f545a35 100644 --- a/Message/Http/HttpResponse.php +++ b/Message/Http/HttpResponse.php @@ -108,7 +108,7 @@ final class HttpResponse extends ResponseAbstract implements RenderableInterface * * @since 1.0.0 */ - public function render(...$data) : string + public function render(mixed ...$data) : string { $types = $this->header->get('Content-Type'); foreach ($types as $type) { diff --git a/Message/Socket/SocketResponse.php b/Message/Socket/SocketResponse.php index 8aa029be1..e7a22b4fa 100644 --- a/Message/Socket/SocketResponse.php +++ b/Message/Socket/SocketResponse.php @@ -90,7 +90,7 @@ final class SocketResponse extends ResponseAbstract implements RenderableInterfa * * @since 1.0.0 */ - public function render(...$data) : string + public function render(mixed ...$data) : string { $types = $this->header->get('Content-Type'); diff --git a/Model/Html/Head.php b/Model/Html/Head.php index 5acda975c..5fc9a8dad 100755 --- a/Model/Html/Head.php +++ b/Model/Html/Head.php @@ -140,7 +140,7 @@ final class Head implements RenderableInterface * * @since 1.0.0 */ - public function render(...$data) : string + public function render(mixed ...$data) : string { $head = ''; $head .= $this->meta->render(); diff --git a/Model/Html/Meta.php b/Model/Html/Meta.php index 12ff827cb..187ee2e06 100644 --- a/Model/Html/Meta.php +++ b/Model/Html/Meta.php @@ -227,7 +227,7 @@ final class Meta implements RenderableInterface /** * {@inheritdoc} */ - public function render(...$data) : string + public function render(mixed ...$data) : string { return (\count($this->keywords) > 0 ? '' : '') . (!empty($this->author) ? '' : '') diff --git a/Views/ViewAbstract.php b/Views/ViewAbstract.php index 80078b01f..7aec3c753 100644 --- a/Views/ViewAbstract.php +++ b/Views/ViewAbstract.php @@ -260,12 +260,22 @@ abstract class ViewAbstract implements RenderableInterface * * @since 1.0.0 */ - public function render(...$data) : string + public function render(mixed ...$data) : string { return $this->renderTemplate($this->template, ...$data); } - protected function renderTemplate(string $template, ...$data) : string + /** + * Render a template file + * + * @param string $template Template path + * @param mixed ...$data Data to pass to renderer + * + * @return string + * + * @since 1.0.0 + */ + protected function renderTemplate(string $template, mixed ...$data) : string { $ob = ''; @@ -310,7 +320,7 @@ abstract class ViewAbstract implements RenderableInterface * * @since 1.0.0 */ - public function build(...$data) : mixed + public function build(mixed ...$data) : mixed { $ob = ''; diff --git a/tests/Message/Http/HttpResponseTest.php b/tests/Message/Http/HttpResponseTest.php index cb6439e23..6c53e6140 100644 --- a/tests/Message/Http/HttpResponseTest.php +++ b/tests/Message/Http/HttpResponseTest.php @@ -218,7 +218,7 @@ final class HttpResponseTest extends \PHPUnit\Framework\TestCase public function testMinimizedRender() : void { $this->response->set('view', new class() extends \phpOMS\Views\View { - public function render(...$data) : string + public function render(mixed ...$data) : string { return " view_string with
text
that has \n whitespaces and \n\nnew lines\n "; } @@ -236,7 +236,7 @@ final class HttpResponseTest extends \PHPUnit\Framework\TestCase public function testInvalidMinimizedRender() : void { $this->response->set('view', new class() extends \phpOMS\Views\View { - public function render(...$data) : string + public function render(mixed ...$data) : string { return " view_string with
text
that has \n whitespaces and \n\nnew lines\n "; } diff --git a/tests/Utils/StringUtilsTest.php b/tests/Utils/StringUtilsTest.php index 033622654..835969c53 100644 --- a/tests/Utils/StringUtilsTest.php +++ b/tests/Utils/StringUtilsTest.php @@ -160,7 +160,7 @@ final class StringUtilsTest extends \PHPUnit\Framework\TestCase })); self::assertEquals('abc', StringUtils::stringify(new class() implements RenderableInterface { - public function render(...$data) : string + public function render(mixed ...$data) : string { return 'abc'; } diff --git a/tests/phpunit_no_coverage.xml b/tests/phpunit_no_coverage.xml index c2e65757c..1125d51fb 100755 --- a/tests/phpunit_no_coverage.xml +++ b/tests/phpunit_no_coverage.xml @@ -25,6 +25,7 @@ ./vendor ./Build ./Resources + ./Application/Testapp*