| Conditions | 1 |
| Paths | 1 |
| Total Lines | 149 |
| Code Lines | 112 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 12 | ||
| Bugs | 4 | Features | 5 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 240 | #[ |
||
| 241 | Get( |
||
| 242 | path: "/posts/filters", |
||
| 243 | operationId: "postGetWithFilter", |
||
| 244 | description: "Get all posts with pagination (10 items per page by default, page 1 by default) |
||
| 245 | |||
| 246 | This API will get records from the database and return them as a paginated list. |
||
| 247 | The default number of items per page is 10 and the default page number is 1. You can change these values by passing the `per_page` and `page` query parameters. |
||
| 248 | ", |
||
| 249 | summary: "Get posts by filter with pagination", |
||
| 250 | tags: ["Post"], |
||
| 251 | parameters: [ |
||
| 252 | new Parameter( |
||
| 253 | name: 'categories', |
||
| 254 | description: 'Filter posts by categories IDs', |
||
| 255 | in: 'query', |
||
| 256 | required: false, |
||
| 257 | schema: new Schema( |
||
| 258 | type: 'array', |
||
| 259 | items: new Items(description: 'Input the category ID', type: 'integer'), |
||
| 260 | default: null, |
||
| 261 | ) |
||
| 262 | ), |
||
| 263 | new Parameter( |
||
| 264 | name: 'categories_exclude', |
||
| 265 | description: 'Filter posts by excluding specific category IDs.', |
||
| 266 | in: 'query', |
||
| 267 | required: false, |
||
| 268 | schema: new Schema( |
||
| 269 | type: 'array', |
||
| 270 | items: new Items(description: 'Input the exclude category ID', type: 'integer'), |
||
| 271 | default: null |
||
| 272 | ) |
||
| 273 | ), |
||
| 274 | new Parameter( |
||
| 275 | name: 'exclude', |
||
| 276 | description: 'Filter posts by excluding specific post IDs.', |
||
| 277 | in: 'query', |
||
| 278 | required: false, |
||
| 279 | schema: new Schema( |
||
| 280 | type: 'array', |
||
| 281 | items: new Items(description: 'Input the exclude post ID', type: 'integer'), |
||
| 282 | default: null |
||
| 283 | ) |
||
| 284 | ), |
||
| 285 | new Parameter( |
||
| 286 | name: 'author', |
||
| 287 | description: 'Filter posts by author IDs', |
||
| 288 | in: 'query', |
||
| 289 | required: false, |
||
| 290 | schema: new Schema( |
||
| 291 | type: 'array', |
||
| 292 | items: new Items(description: 'Input the author ID', type: 'integer'), |
||
| 293 | default: null |
||
| 294 | ) |
||
| 295 | ), |
||
| 296 | new Parameter( |
||
| 297 | name: 'author_exclude', |
||
| 298 | description: 'Filter posts by excluding specific author IDs.', |
||
| 299 | in: 'query', |
||
| 300 | required: false, |
||
| 301 | schema: new Schema( |
||
| 302 | type: 'array', |
||
| 303 | items: new Items(description: 'Input the exclude author ID', type: 'integer'), |
||
| 304 | default: null |
||
| 305 | ) |
||
| 306 | ), |
||
| 307 | new Parameter( |
||
| 308 | name: 'featured', |
||
| 309 | description: 'Filter posts by featured status. Accepts values: |
||
| 310 | 1 for featured posts |
||
| 311 | 0 for non-featured posts.', |
||
| 312 | in: 'query', |
||
| 313 | required: false, |
||
| 314 | schema: new Schema( |
||
| 315 | type: 'integer', |
||
| 316 | default: null, |
||
| 317 | enum: [0, 1], |
||
| 318 | nullable: true |
||
| 319 | ) |
||
| 320 | ), |
||
| 321 | new Parameter( |
||
| 322 | name: 'search', |
||
| 323 | description: 'Search for posts where the given keyword appears in either the name or description fields.', |
||
| 324 | in: 'query', |
||
| 325 | required: false, |
||
| 326 | schema: new Schema(type: 'string', default: null) |
||
| 327 | ), |
||
| 328 | new Parameter( |
||
| 329 | name: 'per_page', |
||
| 330 | description: 'Number of items per page', |
||
| 331 | in: 'query', |
||
| 332 | required: false, |
||
| 333 | schema: new Schema(type: 'integer', default: 10) |
||
| 334 | ), |
||
| 335 | new Parameter( |
||
| 336 | name: 'page', |
||
| 337 | description: 'Page number', |
||
| 338 | in: 'query', |
||
| 339 | required: false, |
||
| 340 | schema: new Schema(type: 'integer', default: 1) |
||
| 341 | ), |
||
| 342 | ], |
||
| 343 | responses: [ |
||
| 344 | new Response( |
||
| 345 | response: 200, |
||
| 346 | description: "Get posts successfully", |
||
| 347 | content: new JsonContent( |
||
| 348 | properties: [ |
||
| 349 | new Property( |
||
| 350 | property: 'error', |
||
| 351 | description: 'Error status', |
||
| 352 | type: 'boolean', |
||
| 353 | default: false |
||
| 354 | ), |
||
| 355 | new Property( |
||
| 356 | property: "data", |
||
| 357 | description: "Data of model", |
||
| 358 | type: "array", |
||
| 359 | items: new Items(ref: PostListResourceSchema::class) |
||
| 360 | ), |
||
| 361 | ] |
||
| 362 | ) |
||
| 363 | ), |
||
| 364 | new Response( |
||
| 365 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\BadRequestResponseSchema::class, |
||
| 366 | response: 400, |
||
| 367 | ), |
||
| 368 | new Response( |
||
| 369 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\ErrorNotFoundResponseSchema::class, |
||
| 370 | response: 404, |
||
| 371 | ), |
||
| 372 | new Response( |
||
| 373 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\InternalServerResponseSchema::class, |
||
| 374 | response: 500, |
||
| 375 | ), |
||
| 376 | ] |
||
| 377 | ) |
||
| 378 | ] |
||
| 379 | public function getFilters(Request $request): BaseHttpResponse|JsonResponse|JsonResource|RedirectResponse |
||
| 380 | { |
||
| 381 | $filters = FilterPost::setFilters($request->input()); |
||
| 382 | |||
| 383 | $data = $this->postRepository->getFilters((array) $filters); |
||
| 384 | |||
| 385 | return $this |
||
| 386 | ->httpResponse() |
||
| 387 | ->setData(ListPostResource::collection($data)) |
||
| 388 | ->toApiResponse(); |
||
| 389 | } |
||
| 391 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths