Skip to content

Feature/carlos turmo application test php#8

Open
zeliuk wants to merge 2 commits intoooptimo:mainfrom
zeliuk:feature/carlos-turmo-application-test-php
Open

Feature/carlos turmo application test php#8
zeliuk wants to merge 2 commits intoooptimo:mainfrom
zeliuk:feature/carlos-turmo-application-test-php

Conversation

@zeliuk
Copy link
Copy Markdown

@zeliuk zeliuk commented Oct 22, 2025

Backend PHP application test - Retrieve API data and display with error handling - Pagination included

Primer de tot he modificat l'arxiu docker-compose.yml (l'atribut version està obsolet) per poder executar el projecte amb Docker. També he canviat el port a 8080 per unificar-ho amb les instruccions de l'exercici.

Respecte a paquets nous, he afegit yii2-httpclient per gestionar les crides a l'API.

A l'hora d'afegir la paginació m'he trobat que JSONPlaceholder utiliza una versió antiga de json-server, per tant els paràmetres per fer la crida dins el model Post no corresponen amb la documentació (paràmetre _limit en comptes de _per_page).

He modificat mínimament el CSS per adaptar colors.

Per executar i accedir a Docker:

docker compose up -d
docker compose exec php bash

Carlos Turmo added 2 commits October 21, 2025 12:02
Copy link
Copy Markdown

@windsurf-bot windsurf-bot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other comments (5)
  • controllers/SiteController.php (49-49) There's no validation to ensure that `$posts` contains the expected 'totalCount' key before using it. Consider adding a check to ensure the data structure is valid before creating the Pagination object.
  • web/css/site.css (69-73) The nested CSS syntax used for the footer selector (`#footer{ .text-muted{ ... } }`) is not valid standard CSS and requires a preprocessor like Sass. If this project doesn't use a CSS preprocessor, this will cause syntax errors. Consider using standard CSS syntax instead:
    #footer .text-muted{
        color: var(--bs-white)!important;
    }
    
  • controllers/SiteController.php (45-45) The `Post::fetchAll()` call doesn't have any error handling. Consider wrapping this in a try-catch block to gracefully handle API failures and provide appropriate feedback to the user.
  • models/Post.php (24-25) Consider removing the unnecessary empty line after the try statement to maintain consistent code style.
  • models/Post.php (78-79) Consider removing the unnecessary empty line before the catch statement to maintain consistent code style.

💡 To request another review, post a new comment with "/windsurf-review".

Comment on lines +70 to +71
// Yii2 log to capture possible API errors
Yii::warning("Error API ({$response->statusCode}): {$message}", __METHOD__);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Yii class is being used for logging but hasn't been imported. Please add use Yii; at the top of the file with the other imports.

/** @var yii\web\View $this */

/* Yii2 pagination widget */
use yii\widgets\LinkPager;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a namespace inconsistency with the LinkPager widget. At the top of the file, you import yii\widgets\LinkPager, but later use \yii\bootstrap5\LinkPager. You should update the import statement to match the actual implementation.

<div class="col-md-12">
<div class="alert alert-danger" role="alert">
<!-- Display the error message -->
<?php echo $posts['message']; ?>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message is being output directly without HTML escaping, which could lead to XSS vulnerabilities if the error message contains HTML tags or scripts.

Suggested change
<?php echo $posts['message']; ?>
<!-- Display the error message -->
<?php echo htmlspecialchars($posts['message']); ?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant