Completed
Pull Request — develop (#259)
by ANTHONIUS
09:01
created

SolrJob::setFacets()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
7
 * @license   MIT
8
 */
9
10
namespace Solr\Entity;
11
12
use Jobs\Entity\Feature\FacetsProviderInterface;
13
use Jobs\Entity\Job;
14
use Jobs\Entity\JobInterface;
15
use Solr\Bridge\Util;
16
17
/**
18
 * Class Job
19
 *
20
 * @author  Anthonius Munthi <[email protected]>
21
 * @since   0.26
22
 * @package Solr\Entity
23
 *
24
 */
25
class SolrJob extends Job implements FacetsProviderInterface
26
{
27
    /**
28
     * @var JobInterface
29
     */
30
    protected $document;
31
32
    /**
33
     * @var \SolrObject
34
     */
35
    protected $result;
36
37
    /**
38
     * @var array
39
     */
40
    protected $facets;
41
42
    public function __construct(JobInterface $job,$solr)
43
    {
44
        $this->document = $job;
45
        $blacklist = ['getPublisher'];
46
        $this->importProperty($blacklist);
47
        $this->result = $solr;
48
    }
49
50
    public function importProperty($blacklist)
51
    {
52
        $document = $this->document;
53
        $methods = get_class_methods($document);
54
        foreach($methods as $method){
55
            if(0 === strpos($method,'get') && !in_array($method,$blacklist)){
56
                $value = call_user_func(array($document,$method));
57
                if(!is_null($value)){
58
                    $setter = 'set'.substr($method,3);
59
                    call_user_func(array($this,$setter),$value);
60
                }
61
            }
62
        }
63
    }
64
65
    /**
66
     * @param $facets
67
     * @return $this
68
     */
69
    public function setFacets($facets)
70
    {
71
        $this->facets = $facets;
72
        return $this;
73
    }
74
75
    /**
76
     * @return array
77
     */
78
    public function getFacets()
79
    {
80
        return $this->facets;
81
    }
82
}