Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
95.74% covered (success)
95.74%
45 / 47
33.33% covered (danger)
33.33%
1 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
CaseStudiesService
95.74% covered (success)
95.74%
45 / 47
33.33% covered (danger)
33.33%
1 / 3
6
0.00% covered (danger)
0.00%
0 / 1
 getCaseStudies
91.67% covered (success)
91.67%
11 / 12
0.00% covered (danger)
0.00%
0 / 1
2.00
 getFileContent
83.33% covered (warning)
83.33%
5 / 6
0.00% covered (danger)
0.00%
0 / 1
3.04
 convertDirName
100.00% covered (success)
100.00%
29 / 29
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Services;
4
5use Illuminate\Support\Collection;
6use Illuminate\Support\Facades\File;
7use GrahamCampbell\Markdown\Facades\Markdown;
8
9class 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}