Passed
Push — sheepy/introspection ( 851cdd...69e16c )
by Marco
06:22
created

QueryRecord   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 13
c 1
b 0
f 0
dl 0
loc 29
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A findOrCreate() 0 13 3
1
<?php
2
3
4
namespace Firesphere\SolrSearch\Models;
5
6
use SilverStripe\ORM\DataObject;
7
use SilverStripe\ORM\ValidationException;
8
9
/**
10
 * Class \Firesphere\SolrSearch\Models\QueryRecording
11
 *
12
 * @property string $Query
13
 * @property int $Results
14
 * @property int $PagesVisited
15
 */
16
class QueryRecord extends DataObject
17
{
18
    private static $table_name = 'QueryRecording';
19
20
    private static $db = [
21
        'Query' => 'Varchar(255)',
22
        'Results' => 'Int',
23
        'PagesVisited' => 'Int',
24
    ];
25
26
    /**
27
     * @param $query
28
     * @param $count
29
     * @return QueryRecord
30
     * @throws ValidationException
31
     */
32
    public static function findOrCreate($query, $count): QueryRecord
33
    {
34
        $item = static::get()->filter(['Query' => trim($query)])->first();
35
        if (!$item || !$item->exists()) {
36
            $item = static::create([
37
                'Query' => $query,
38
            ]);
39
        }
40
        $item->Results = $count;
41
42
        $item->write();
43
44
        return $item;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $item returns the type SilverStripe\ORM\DataObject which includes types incompatible with the type-hinted return Firesphere\SolrSearch\Models\QueryRecord.
Loading history...
45
    }
46
}
47