Completed
Pull Request — develop (#480)
by Carsten
05:32
created

ApiJobDehydrator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 80
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUrl() 0 5 1
A setJobUrl() 0 5 1
A dehydrate() 0 22 1
A dehydrateList() 0 9 2
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2016 Cross Solution <http://cross-solution.de>
8
 */
9
10
namespace Jobs\Model;
11
12
use Jobs\Entity\Job;
13
use Zend\View\Helper\Url;
14
use Jobs\View\Helper\JobUrl;
15
16
class ApiJobDehydrator
17
{
18
    /**
19
     * ViewHelper for generating an url
20
     *
21
     * @var Url $url
22
     */
23
    protected $url;
24
25
  /**
26
   * ViewHelper for generating an url to a job posting
27
   *
28
   * @var JobUrl $jobUrl
29
   */
30
    protected $jobUrl;
31
32
    /**
33
     * @param Url $url
34
     *
35
     * @return $this
36
     */
37
    public function setUrl($url)
38
    {
39
        $this->url = $url;
40
        return $this;
41
    }
42
43
   /**
44
    * @param JobUrl $url
45
    *
46
    * @return $this
47
    */
48
    public function setJobUrl($url)
49
    {
50
        $this->jobUrl = $url;
51
        return $this;
52
    }
53
54
    /**
55
     * @param Job $job
56
     *
57
     * @return array
58
     */
59
    public function dehydrate(Job $job)
60
    {
61
        return array(
62
            'datePublishStart' => $job->getDatePublishStart(),
63
            'title' => $job->getTitle(),
64
            'location' => $job->getLocation(),
65
            'link' => $this->jobUrl->__invoke(
66
                $job,[
67
                  'linkOnly'=> true,
68
                  'absolute' => true,
69
                ]
70
            ),
71
            'organization' => array(
72
                'name' => $job->getOrganization()->getOrganizationName()->getName(),
73
            ),
74
            'template_values' => array(
75
                'requirements' => $job->getTemplateValues()->getRequirements(),
76
                'qualification' => $job->getTemplateValues()->getQualifications(),
77
                'benefits' => $job->getTemplateValues()->getBenefits()
78
            )
79
        );
80
    }
81
82
    /**
83
     * @param Job[] $jobs
84
     * @return array
85
     */
86
    public function dehydrateList(array $jobs)
87
    {
88
        $result = [];
89
        foreach ($jobs as $job) {
90
            $result[] = $this->dehydrate($job);
91
        }
92
93
        return $result;
94
    }
95
}
96