Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
95.74% |
45 / 47 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
CaseStudiesService | |
95.74% |
45 / 47 |
|
33.33% |
1 / 3 |
6 | |
0.00% |
0 / 1 |
getCaseStudies | |
91.67% |
11 / 12 |
|
0.00% |
0 / 1 |
2.00 | |||
getFileContent | |
83.33% |
5 / 6 |
|
0.00% |
0 / 1 |
3.04 | |||
convertDirName | |
100.00% |
29 / 29 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace App\Services; |
4 | |
5 | use Illuminate\Support\Collection; |
6 | use Illuminate\Support\Facades\File; |
7 | use GrahamCampbell\Markdown\Facades\Markdown; |
8 | |
9 | class CaseStudiesService |
10 | { |
11 | public function getCaseStudies(): Collection |
12 | { |
13 | $directory = base_path() . "/public/cs"; |
14 | if (is_dir($directory)) { |
15 | $publicFolders = File::directories($directory); |
16 | return collect($publicFolders)->map(function ($folder) { |
17 | $folderName = $this->convertDirName(basename($folder)); |
18 | $files = File::files($folder); |
19 | return [ |
20 | 'name' => $folderName, |
21 | 'files' => $files, |
22 | ]; |
23 | }); |
24 | } |
25 | return collect([]); |
26 | } |
27 | |
28 | public function getFileContent(string $file): string | null |
29 | { |
30 | $filePath = base_path() . "/public/" . base64_decode($file); |
31 | if (File::exists($filePath)) { |
32 | $extension = File::extension($filePath); |
33 | $content = File::get($filePath); |
34 | return ($extension === 'md') ? Markdown::convertToHtml($content) : $content; |
35 | } |
36 | return null; |
37 | } |
38 | |
39 | private function convertDirName(string $name): string |
40 | { |
41 | return match ($name) |
42 | { |
43 | "0presentation" => "๐๏ธ Presentation of this project ##DONE##", |
44 | "0setup" => "โ๏ธ Prod env setup AKA Adilia! ##DONE##", |
45 | "1basic-setup" => "๐ป Local env setup AKA Ready to Dev! ##DONE##", |
46 | "2.1ci-cd" => "๐ค๏ธ CI / CD with jenkins ##DONE##", |
47 | "2.2git-rule" => "๐งฉ GitHub protection rule for master branch ##DONE##", |
48 | "2.3wms" => "๐ฉ Website message service with Rabbitmq ##DONE##", |
49 | "2.4gc-bucket" => "โ๏ธ Do backups to a bucket using google cloud ##DONE##", |
50 | "3hide-routes-cookie" => "๐ Hide routes in production ##DONE##", |
51 | "4maintenance-mode" => "๐๏ธ Site down in maintenance mode accessible only for devs ##DONE##", |
52 | "5env_vars_without" => "๐ Hide env vars ##DONE##", |
53 | "6webpack-mix" => "๐งโ๐ป JS + CSS assets compile/minify + Handle with client browser caches with versioning ##DONE##", |
54 | "7rate-limit" => "๐ฎโโ๏ธ Requests limit per route per user + rate limit security with Throttle ##DONE##", |
55 | "8logging" => "๐๏ธ Laravel custom log files ##DONE##", |
56 | "9.0error-pages" => "๐ Laravel custom error views ##DONE##", |
57 | "9.0.1redis" => "๐ฟ Redis implementation ##STARTED_NOT_DONE##", |
58 | "9.1swagger" => "๐น๏ธ Swagger implementation ##DONE##", |
59 | "9.2reboot-cron" => "โ๏ธ Some jobs in prod ##STARTED_NOT_DONE##", |
60 | "9.3unit-tests" => "๐งช Phpunit tests ##DONE##", |
61 | "9.4es" => "๐ Elasticsearch implementation ##STARTED_NOT_DONE##", |
62 | "9.5apc" => "๐ฟ APCu implementation ##NOT_STARTED##", |
63 | "9.5caches" => "๐ฟ Backend cache system implementation for load balanced with multiple frontends ##DONE##", |
64 | "9.6auth2" => "๐ Implementation of authentication with Sanctum ( Token management ) ##DONE##", |
65 | "9.7i18n" => "๐ Implementation of a translation system with the possibility to manage the translations in the private area ##STARTED_NOT_DONE##", |
66 | "9.7areas_for_admins" => "๐ Special routes only accessible for some users ##STARTED_NOT_DONE##", |
67 | "9.8dashboard" => "๐ Dashboard with the system status accessible only for admins ##STARTED_NOT_DONE##", |
68 | default => $name, |
69 | }; |
70 | } |
71 | } |