akubiczek /
applicake-backend
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Utils; |
||
| 4 | |||
| 5 | use App\Models\Candidate; |
||
| 6 | use Carbon\Carbon; |
||
| 7 | |||
| 8 | class ContentParser |
||
| 9 | { |
||
| 10 | public static function parse(string $content, Candidate $candidate, \DateTime $appointmentDate = null, $user = null) |
||
| 11 | { |
||
| 12 | $mapping = [ |
||
| 13 | '%%JOB_TITLE%%' => $candidate->recruitment->job_title, |
||
| 14 | '%%CANDIDATE_NAME%%' => $candidate->name, |
||
| 15 | '%%USER_FIRST_NAME%%' => $user ? $user->name : '', |
||
| 16 | '%%USER_LAST_NAME%%' => '', |
||
| 17 | '%%APPOINTMENT_NATURAL_DATE%%' => $appointmentDate ? self::naturalDate($appointmentDate) : '', |
||
| 18 | '%%APPOINTMENT_DATE%%' => $appointmentDate ? self::formattedDate($appointmentDate) : '', |
||
| 19 | '%%APPOINTMENT_TIME%%' => $appointmentDate ? $appointmentDate->format('G:i') : '', |
||
| 20 | ]; |
||
| 21 | |||
| 22 | foreach ($mapping as $variable => $value) { |
||
| 23 | $content = str_replace($variable, $value, $content); |
||
| 24 | } |
||
| 25 | |||
| 26 | return $content; |
||
| 27 | } |
||
| 28 | |||
| 29 | protected static function naturalDate($date) |
||
| 30 | { |
||
| 31 | $prefix = ''; |
||
| 32 | $carbonDate = Carbon::instance($date)->locale('pl_PL'); |
||
| 33 | $carbonDateYesterday = $carbonDate->copy(); |
||
| 34 | |||
| 35 | if ($carbonDate->isTomorrow()) { |
||
| 36 | $prefix = 'jutro, tj. '; |
||
| 37 | } elseif ($carbonDateYesterday->subDay(1)->isTomorrow()) { |
||
|
0 ignored issues
–
show
|
|||
| 38 | $prefix = 'pojutrze, tj. '; |
||
| 39 | } |
||
| 40 | |||
| 41 | return $prefix.$carbonDate->isoFormat('dddd, D MMMM'); |
||
| 42 | } |
||
| 43 | |||
| 44 | protected static function formattedDate($date) |
||
| 45 | { |
||
| 46 | $carbonDate = Carbon::instance($date)->locale('pl_PL'); |
||
| 47 | |||
| 48 | return $carbonDate->isoFormat('dddd, D MMMM'); |
||
| 49 | } |
||
| 50 | } |
||
| 51 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.