Skip to content

Add missing return types #2734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 13, 2025
Merged

Add missing return types #2734

merged 2 commits into from
May 13, 2025

Conversation

mnocon
Copy link
Contributor

@mnocon mnocon commented May 8, 2025

Target: master only

PHPStan errors on master:

  Line   api/rest_api/src/Rest/InputParser/GreetingInput.php                                                                                                                    
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  :12    Method App\Rest\InputParser\GreetingInput::parse() has no return type specified.                                                                                       
         🪪  missingType.return                                                                                                                                                 
  :12    Return type mixed of method App\Rest\InputParser\GreetingInput::parse() is not covariant with return type mixed of method Ibexa\Contracts\Rest\Input\Parser::parse().  
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

 ------ -------------------------------------------------------------------------------------------------------------------------------- 
  Line   api/rest_api/src/Rest/ValueObjectVisitor/RestLocation.php                                                                       
 ------ -------------------------------------------------------------------------------------------------------------------------------- 
  :20    Return type mixed of method App\Rest\ValueObjectVisitor\RestLocation::visit() is not covariant with return type void of method  
         Ibexa\Rest\Server\Output\ValueObjectVisitor\RestLocation::visit().              

Parent definitions:
https://github.com/ibexa/rest/blob/main/src/contracts/Input/Parser.php#L20
https://github.com/ibexa/rest/blob/main/src/lib/Server/Output/ValueObjectVisitor/RestLocation.php#L27

@mnocon mnocon changed the title Add missing code samples Add missing return types May 8, 2025
@mnocon mnocon force-pushed the add-missing-code-samples branch from 40d64f3 to 5cbc48b Compare May 8, 2025 14:13
@mnocon mnocon marked this pull request as ready for review May 8, 2025 14:14
@mnocon mnocon requested a review from ViniTou May 8, 2025 14:14
Copy link

github-actions bot commented May 8, 2025

Preview of modified files: no change to preview.

@mnocon mnocon requested a review from adriendupuis May 12, 2025 09:32
Co-authored-by: Dawid Parafiński <dawid.parafinski@ez.no>
Copy link

code_samples/ change report

Before (on target branch)After (in current PR)

code_samples/api/rest_api/src/Rest/InputParser/GreetingInput.php

docs/api/rest_api/extending_rest_api/creating_new_rest_resource.md@113:``` php
docs/api/rest_api/extending_rest_api/creating_new_rest_resource.md@114:[[= include_file('code_samples/api/rest_api/src/Rest/InputParser/GreetingInput.php') =]]
docs/api/rest_api/extending_rest_api/creating_new_rest_resource.md@115:```

001⫶<?php declare(strict_types=1);
002⫶
003⫶namespace App\Rest\InputParser;
004⫶
005⫶use App\Rest\Values\Greeting;
006⫶use Ibexa\Contracts\Rest\Exceptions;
007⫶use Ibexa\Contracts\Rest\Input\ParsingDispatcher;
008⫶use Ibexa\Rest\Input\BaseParser;
009⫶
010⫶class GreetingInput extends BaseParser
011⫶{

code_samples/api/rest_api/src/Rest/InputParser/GreetingInput.php

docs/api/rest_api/extending_rest_api/creating_new_rest_resource.md@113:``` php
docs/api/rest_api/extending_rest_api/creating_new_rest_resource.md@114:[[= include_file('code_samples/api/rest_api/src/Rest/InputParser/GreetingInput.php') =]]
docs/api/rest_api/extending_rest_api/creating_new_rest_resource.md@115:```

001⫶<?php declare(strict_types=1);
002⫶
003⫶namespace App\Rest\InputParser;
004⫶
005⫶use App\Rest\Values\Greeting;
006⫶use Ibexa\Contracts\Rest\Exceptions;
007⫶use Ibexa\Contracts\Rest\Input\ParsingDispatcher;
008⫶use Ibexa\Rest\Input\BaseParser;
009⫶
010⫶class GreetingInput extends BaseParser
011⫶{
012⫶    public function parse(array $data, ParsingDispatcher $parsingDispatcher)
012⫶    public function parse(array $data, ParsingDispatcher $parsingDispatcher): Greeting
013⫶    {
014⫶ if (!isset($data['Salutation'])) {
015⫶ throw new Exceptions\Parser("Missing or invalid 'Salutation' element for Greeting.");
016⫶ }
017⫶
018⫶ return new Greeting($data['Salutation'], $data['Recipient'] ?? 'World');
019⫶ }
020⫶}


code_samples/api/rest_api/src/Rest/ValueObjectVisitor/RestLocation.php

docs/api/rest_api/extending_rest_api/adding_custom_media_type.md@34:``` php
docs/api/rest_api/extending_rest_api/adding_custom_media_type.md@35:[[= include_file('code_samples/api/rest_api/src/Rest/ValueObjectVisitor/RestLocation.php') =]]
docs/api/rest_api/extending_rest_api/adding_custom_media_type.md@36:```

001⫶<?php declare(strict_types=1);
002⫶
003⫶namespace App\Rest\ValueObjectVisitor;
004⫶
005⫶use Ibexa\Contracts\Core\Repository\URLAliasService;
006⫶use Ibexa\Contracts\Rest\Output\Generator;
007⫶use Ibexa\Contracts\Rest\Output\Visitor;
008⫶use Ibexa\Rest\Server\Output\ValueObjectVisitor\RestLocation as BaseRestLocation;
009⫶use Ibexa\Rest\Server\Values\URLAliasRefList;
010⫶
011⫶class RestLocation extends BaseRestLocation
012⫶{
013⫶ private URLAliasService $urlAliasService;
014⫶
015⫶ public function __construct(URLAliasService $urlAliasService)
016⫶ {
017⫶ $this->urlAliasService = $urlAliasService;
018⫶ }
019⫶
013⫶    {
014⫶ if (!isset($data['Salutation'])) {
015⫶ throw new Exceptions\Parser("Missing or invalid 'Salutation' element for Greeting.");
016⫶ }
017⫶
018⫶ return new Greeting($data['Salutation'], $data['Recipient'] ?? 'World');
019⫶ }
020⫶}


code_samples/api/rest_api/src/Rest/ValueObjectVisitor/RestLocation.php

docs/api/rest_api/extending_rest_api/adding_custom_media_type.md@34:``` php
docs/api/rest_api/extending_rest_api/adding_custom_media_type.md@35:[[= include_file('code_samples/api/rest_api/src/Rest/ValueObjectVisitor/RestLocation.php') =]]
docs/api/rest_api/extending_rest_api/adding_custom_media_type.md@36:```

001⫶<?php declare(strict_types=1);
002⫶
003⫶namespace App\Rest\ValueObjectVisitor;
004⫶
005⫶use Ibexa\Contracts\Core\Repository\URLAliasService;
006⫶use Ibexa\Contracts\Rest\Output\Generator;
007⫶use Ibexa\Contracts\Rest\Output\Visitor;
008⫶use Ibexa\Rest\Server\Output\ValueObjectVisitor\RestLocation as BaseRestLocation;
009⫶use Ibexa\Rest\Server\Values\URLAliasRefList;
010⫶
011⫶class RestLocation extends BaseRestLocation
012⫶{
013⫶ private URLAliasService $urlAliasService;
014⫶
015⫶ public function __construct(URLAliasService $urlAliasService)
016⫶ {
017⫶ $this->urlAliasService = $urlAliasService;
018⫶ }
019⫶
020⫶    public function visit(Visitor $visitor, Generator $generator, $data)
020⫶    public function visit(Visitor $visitor, Generator $generator, $data): void
021⫶    {
022⫶ // Not using $generator->startObjectElement to not have the XML Generator adding its own media-type attribute with the default vendor
023⫶ $generator->startHashElement('Location');
024⫶ $generator->attribute(
025⫶ 'media-type',
026⫶ 'application/app.api.Location+' . strtolower((new \ReflectionClass($generator))->getShortName())
027⫶ );
028⫶ $generator->attribute(
029⫶ 'href',
030⫶ $this->router->generate(
031⫶ 'ibexa.rest.load_location',
032⫶ ['locationPath' => trim($data->location->pathString, '/')]
033⫶ )
034⫶ );
035⫶ parent::visit($visitor, $generator, $data);
036⫶ $visitor->visitValueObject(new URLAliasRefList(array_merge(
037⫶ $this->urlAliasService->listLocationAliases($data->location, false),
038⫶ $this->urlAliasService->listLocationAliases($data->location, true)
039⫶ ), $this->router->generate(
040⫶ 'ibexa.rest.list_location_url_aliases',
041⫶ ['locationPath' => trim($data->location->pathString, '/')]
042⫶ )));
043⫶ $generator->endHashElement('Location');
044⫶ }
045⫶}

021⫶    {
022⫶ // Not using $generator->startObjectElement to not have the XML Generator adding its own media-type attribute with the default vendor
023⫶ $generator->startHashElement('Location');
024⫶ $generator->attribute(
025⫶ 'media-type',
026⫶ 'application/app.api.Location+' . strtolower((new \ReflectionClass($generator))->getShortName())
027⫶ );
028⫶ $generator->attribute(
029⫶ 'href',
030⫶ $this->router->generate(
031⫶ 'ibexa.rest.load_location',
032⫶ ['locationPath' => trim($data->location->pathString, '/')]
033⫶ )
034⫶ );
035⫶ parent::visit($visitor, $generator, $data);
036⫶ $visitor->visitValueObject(new URLAliasRefList(array_merge(
037⫶ $this->urlAliasService->listLocationAliases($data->location, false),
038⫶ $this->urlAliasService->listLocationAliases($data->location, true)
039⫶ ), $this->router->generate(
040⫶ 'ibexa.rest.list_location_url_aliases',
041⫶ ['locationPath' => trim($data->location->pathString, '/')]
042⫶ )));
043⫶ $generator->endHashElement('Location');
044⫶ }
045⫶}

Download colorized diff

@mnocon mnocon merged commit b2101d2 into master May 13, 2025
6 of 7 checks passed
@mnocon mnocon deleted the add-missing-code-samples branch May 13, 2025 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants