Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
60.00% covered (warning)
60.00%
12 / 20
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
Decoder
60.00% covered (warning)
60.00%
12 / 20
0.00% covered (danger)
0.00%
0 / 2
10.14
0.00% covered (danger)
0.00%
0 / 1
 decodeSeconds
55.56% covered (warning)
55.56%
5 / 9
0.00% covered (danger)
0.00%
0 / 1
3.79
 decodeSuccess
63.64% covered (warning)
63.64%
7 / 11
0.00% covered (danger)
0.00%
0 / 1
4.77
1<?php
2
3class Decoder
4{
5    public static function decodeSeconds($previousTsumego): ?float
6    {
7        $secondsCheck = Util::clearRequiredNumericCookie('secondsCheck');
8
9        if ($secondsCheck % 79 != 0)
10        {
11            Auth::addSuspicion();
12            return null;
13        }
14        $secondsCheck /= 79;
15        if ($secondsCheck % $previousTsumego['Tsumego']['id'] != 0)
16        {
17            Auth::addSuspicion();
18            return null;
19        }
20        return ($secondsCheck / $previousTsumego['Tsumego']['id']) / 100;
21    }
22
23    public static function decodeSuccess($previousTsumegoID): bool
24    {
25        $solvedCheck = Util::clearCookie('solvedCheck');
26        if (empty($solvedCheck))
27            return false;
28
29        $decryptedSolvedCheck = explode('-', Util::decrypt($solvedCheck));
30        if (count($decryptedSolvedCheck) != 2)
31        {
32            Auth::addSuspicion();
33            return false;
34        }
35        if ($decryptedSolvedCheck[0] != $previousTsumegoID)
36        {
37            Auth::addSuspicion();
38            return false;
39        }
40        return true;
41    }
42}