ReportReviewsTotalsController::get_reports()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 17
ccs 0
cts 14
cp 0
rs 9.9
c 0
b 0
f 0
cc 3
nc 3
nop 0
crap 12
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Integrations\WooCommerce\Controllers\RestApi;
4
5
class ReportReviewsTotalsController extends \WC_REST_Report_Reviews_Totals_Controller
6
{
7
    /**
8
     * @return array
9
     */
10
    protected function get_reports()
11
    {
12
        $ratings = glsr_get_ratings([
13
            'assigned_posts' => 'product',
14
        ]);
15
        $data = [];
16
        foreach ($ratings->ratings as $rating => $total) {
17
            if ($rating < 1) {
18
                continue;
19
            }
20
            $data[] = [
21
                'slug' => sprintf('rated_%s_out_of_5', $rating),
22
                'name' => sprintf(__('Rated %s out of 5', 'woocommerce'), $rating),
23
                'total' => $total,
24
            ];
25
        }
26
        return $data;
27
    }
28
}
29