This repository contains the solutions to scnip backend developer assessment role.
This guide assumed you have PHP 8.2+ and Composer installed on your pc.
Clone this repository and navigate into it:
git clone https://github.com/iamolayemi/scnip-assessment.git
cd scnip-assessment
composer install
To run the example script:
php main.php
This should display a formatted output similar to the one below in the console.
Products Without Sorting
+----+-----------------+-------+-------------+-------------+------------+
| ID | Name | Price | Sales Count | Views Count | Created At |
+----+-----------------+-------+-------------+-------------+------------+
| 1 | Alabaster Table | 12.99 | 32 | 730 | 2019-01-04 |
| 2 | Zebra Table | 44.49 | 301 | 3279 | 2012-01-04 |
| 3 | Coffee Table | 10 | 1048 | 20123 | 2014-05-28 |
+----+-----------------+-------+-------------+-------------+------------+
Products Sorted By Price
+----+-----------------+-------+-------------+-------------+------------+
| ID | Name | Price | Sales Count | Views Count | Created At |
+----+-----------------+-------+-------------+-------------+------------+
| 3 | Coffee Table | 10 | 1048 | 20123 | 2014-05-28 |
| 1 | Alabaster Table | 12.99 | 32 | 730 | 2019-01-04 |
| 2 | Zebra Table | 44.49 | 301 | 3279 | 2012-01-04 |
+----+-----------------+-------+-------------+-------------+------------+
Products Sorted By Sales Per View
+----+-----------------+-------+-------------+-------------+------------+
| ID | Name | Price | Sales Count | Views Count | Created At |
+----+-----------------+-------+-------------+-------------+------------+
| 1 | Alabaster Table | 12.99 | 32 | 730 | 2019-01-04 |
| 3 | Coffee Table | 10 | 1048 | 20123 | 2014-05-28 |
| 2 | Zebra Table | 44.49 | 301 | 3279 | 2012-01-04 |
+----+-----------------+-------+-------------+-------------+------------+
You can open and edit the main.php
file with your preferred IDE or code editor to experiment with different sorting scenarios.
To add a new sorter, follow these steps:
- Create a new class in the
src/Sorters
folder that implements theProductSorter
interface. - Implement the
sort
method in the new sorter class.
To run unit tests, execute the following command:
composer test