|
3 | 3 |
|
4 | 4 | namespace CrudJsonApi\Listener; |
5 | 5 |
|
6 | | -use Cake\Core\Configure; |
7 | 6 | use Cake\Datasource\EntityInterface; |
8 | 7 | use Cake\Datasource\RepositoryInterface; |
9 | 8 | use Cake\Datasource\ResultSetDecorator; |
10 | 9 | use Cake\Datasource\ResultSetInterface; |
11 | 10 | use Cake\Event\EventInterface; |
12 | 11 | use Cake\Http\Exception\BadRequestException; |
| 12 | +use Cake\Http\Exception\MethodNotAllowedException; |
13 | 13 | use Cake\Http\Response; |
14 | 14 | use Cake\ORM\Association; |
15 | 15 | use Cake\ORM\Query; |
@@ -110,28 +110,6 @@ public function implementedEvents(): array |
110 | 110 | ]; |
111 | 111 | } |
112 | 112 |
|
113 | | - /** |
114 | | - * setup |
115 | | - * |
116 | | - * Called when the listener is created |
117 | | - * |
118 | | - * @return void |
119 | | - */ |
120 | | - public function setup(): void |
121 | | - { |
122 | | - if (!$this->_checkRequestType('jsonapi')) { |
123 | | - return; |
124 | | - } |
125 | | - |
126 | | - $appClass = Configure::read('App.namespace') . '\Application'; |
127 | | - |
128 | | - // If `App\Application` class exists it means Cake 3.3's PSR7 middleware |
129 | | - // implementation is used and it's too late to register new error handler. |
130 | | - if (!class_exists($appClass, false)) { |
131 | | - $this->registerExceptionHandler(); |
132 | | - } |
133 | | - } |
134 | | - |
135 | 113 | /** |
136 | 114 | * beforeHandle |
137 | 115 | * |
@@ -435,7 +413,7 @@ protected function _includeParameter($includes, Subject $subject, $options): voi |
435 | 413 | } |
436 | 414 |
|
437 | 415 | if ($options['blacklist'] === true || $options['whitelist'] === false) { |
438 | | - throw new BadRequestException("The include parameter is not supported"); |
| 416 | + throw new BadRequestException('The include parameter is not supported'); |
439 | 417 | } |
440 | 418 |
|
441 | 419 | $this->setConfig('include', []); |
@@ -790,25 +768,23 @@ protected function _validateConfigOptions(): void |
790 | 768 | * Override ApiListener method to enforce required JSON API request methods. |
791 | 769 | * |
792 | 770 | * @throws \Cake\Http\Exception\BadRequestException |
793 | | - * @return bool |
| 771 | + * @return void |
794 | 772 | */ |
795 | | - protected function _checkRequestMethods(): bool |
| 773 | + protected function _checkRequestMethods(): void |
796 | 774 | { |
797 | 775 | if ($this->_request()->is('put')) { |
798 | | - throw new BadRequestException('JSON API does not support the PUT method, use PATCH instead'); |
| 776 | + throw new MethodNotAllowedException('JSON API does not support the PUT method, use PATCH instead'); |
799 | 777 | } |
800 | 778 |
|
801 | 779 | if (!$this->_request()->contentType()) { |
802 | | - return true; |
| 780 | + return; |
803 | 781 | } |
804 | 782 |
|
805 | 783 | if ($this->_request()->contentType() !== self::MIME_TYPE) { |
806 | 784 | throw new BadRequestException( |
807 | 785 | 'JSON API requests with data require the "' . self::MIME_TYPE . '" Content-Type header' |
808 | 786 | ); |
809 | 787 | } |
810 | | - |
811 | | - return true; |
812 | 788 | } |
813 | 789 |
|
814 | 790 | /** |
@@ -866,11 +842,11 @@ protected function _getFindResult(Subject $subject) |
866 | 842 | * |
867 | 843 | * @param \Crud\Event\Subject $subject Subject |
868 | 844 | * @return \Cake\Datasource\EntityInterface|null |
869 | | - * @phpstan-ignore |
870 | 845 | */ |
871 | 846 | protected function _getSingleEntity(Subject $subject): ?EntityInterface |
872 | 847 | { |
873 | 848 | if (!empty($subject->entities) && $subject->entities instanceof Query) { |
| 849 | + // @phpstan-ignore-next-line |
874 | 850 | return (clone $subject->entities)->first(); |
875 | 851 | } |
876 | 852 |
|
@@ -987,7 +963,7 @@ protected function _getRepositoryList(RepositoryInterface $repository, array $as |
987 | 963 | ]; |
988 | 964 |
|
989 | 965 | if ($association['association'] === null) { |
990 | | - throw new InvalidArgumentException("Association does not have an association object set"); |
| 966 | + throw new InvalidArgumentException('Association does not have an association object set'); |
991 | 967 | } |
992 | 968 |
|
993 | 969 | $associationRepository = $association['association']->getTarget(); |
|
0 commit comments