| Conditions | 5 |
| Paths | 9 |
| Total Lines | 24 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 17 | public function run($rating1, $rating2) |
||
| 18 | { |
||
| 19 | $dotProduct = 0; |
||
| 20 | $sqrLenght1 = 0; |
||
| 21 | foreach ($rating1 as $item => $rating) { |
||
| 22 | if (!isset($rating2[$item])) { |
||
| 23 | continue; |
||
| 24 | } |
||
| 25 | $sqrLenght1 += pow($rating, 2); |
||
| 26 | $dotProduct += $rating * $rating2[$item]; |
||
| 27 | } |
||
| 28 | if (!$sqrLenght1) { |
||
| 29 | return false; |
||
| 30 | } |
||
| 31 | $length1 = sqrt($sqrLenght1); |
||
| 32 | |||
| 33 | $sqrLength2 = 0; |
||
| 34 | foreach ($rating2 as $item => $rating) { |
||
| 35 | $sqrLength2 += pow($rating, 2); |
||
| 36 | } |
||
| 37 | $length2 = sqrt($sqrLength2); |
||
| 38 | |||
| 39 | return 1 - abs($dotProduct / ($length1 * $length2)); |
||
| 40 | } |
||
| 41 | } |
||
| 42 |