Completed
Push — develop ( 346ce9...ffa440 )
by
unknown
31:53 queued 20:25
created

setOrganizationInfo()   C

Complexity

Conditions 7
Paths 9

Size

Total Lines 42
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 42
rs 6.7273
cc 7
eloc 35
nc 9
nop 0
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013-2015 Cross Solution (http://cross-solution.de)
7
 * @license   MIT
8
 * @author    [email protected]
9
 */
10
11
12
namespace Jobs\Filter;
13
14
use Jobs\Entity\Job;
15
use Zend\Filter\FilterInterface;
16
use Zend\View\Model\ViewModel;
17
18
/**
19
 * assembles a ViewModel for job templates.
20
 * this class needs to be extended for specific assignments
21
 * Class viewModelTemplateFilterAbstract
22
 * @package Jobs\Filter
23
 */
24
abstract class ViewModelTemplateFilterAbstract implements FilterInterface
0 ignored issues
show
Coding Style introduced by
ViewModelTemplateFilterAbstract does not seem to conform to the naming convention (^Abstract|Factory$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
25
{
26
27
    /**
28
     * @var array assembles all data for the viewmodel
29
     */
30
    protected $container;
31
32
    /**
33
     * @var Job
34
     */
35
    protected $job;
36
37
    /**
38
     * @var array
39
     */
40
    protected $config;
41
42
    /**
43
     * creating absolute links like the apply-link
44
     * absolute links are needed on the server of the provider
45
     * @var
46
     */
47
    protected $urlPlugin;
48
49
    /**
50
     * also needed to create absolute links
51
     * @var
52
     */
53
    protected $basePathHelper;
54
55
    /**
56
     * @var
57
     */
58
    protected $serverUrlHelper;
59
60
    /**
61
     * @param $config
62
     */
63
    public function setConfig($config)
64
    {
65
        $this->config = $config;
66
        return;
67
    }
68
69
    /**
70
     * @param $urlPlugin
71
     */
72
    public function setUrlPlugin($urlPlugin)
73
    {
74
        $this->urlPlugin = $urlPlugin;
75
        return;
76
    }
77
78
    /**
79
     * @param $basePathHelper
80
     */
81
    public function setBasePathHelper($basePathHelper)
82
    {
83
        $this->basePathHelper = $basePathHelper;
84
        return;
85
    }
86
87
    /**
88
     * @return mixed
89
     */
90
    public function getBasePathHelper()
91
    {
92
        return $this->basePathHelper;
93
    }
94
95
    /**
96
     * @param $serverUrlHelper
97
     */
98
    public function setServerUrlHelper($serverUrlHelper)
99
    {
100
        $this->serverUrlHelper = $serverUrlHelper;
101
        return;
102
    }
103
104
    /**
105
     * @return mixed
106
     */
107
    public function getServerUrlHelper()
108
    {
109
        return $this->serverUrlHelper;
110
    }
111
112
    /**
113
     * @param mixed $value
114
     * @return mixed|ViewModel
115
     * @throws \InvalidArgumentException
116
     */
117
    public function filter($value)
118
    {
119
        $model = new ViewModel();
120
        $this->container = array();
121
        $this->extract($value);
122
        $model->setVariables($this->container);
123
        if (!isset($this->job)) {
124
            throw new \InvalidArgumentException('cannot create a viewModel for Templates without an $job');
125
        }
126
        $model->setTemplate('templates/' . $this->job->getTemplate() . '/index');
127
        return $model;
128
    }
129
130
    /**
131
     * should be overwritten
132
     * here are all assignments to container arr administered
133
     * input-attributes are the job and the configuration
134
     * output-attribute is the container
135
     * @param $value
136
     * @return mixed
137
     */
138
    abstract protected function extract($value);
139
140
    /**
141
     * Set the apply button of the job posting
142
     *
143
     * @return $this
144
     * @throws \InvalidArgumentException
145
     */
146
    protected function setUriApply()
147
    {
148
        if (!isset($this->job)) {
149
            throw new \InvalidArgumentException('cannot create a viewModel for Templates without a $job');
150
        }
151
        $atsMode = $this->job->getAtsMode();
152
        $uriApply = false;
153
        if ($atsMode->isIntern() || $atsMode->isEmail()) {
154
            $uriApply = $this->urlPlugin->fromRoute('lang/apply', array('applyId' => $this->job->getApplyId()), array('force_canonical' => true));
155
        } elseif ($atsMode->isUri()) {
156
            $uriApply = $atsMode->getUri();
157
        }
158
        $this->container['uriApply'] = $uriApply;
159
        return $this;
160
    }
161
162
    /**
163
     * Sets the location of a jobs
164
     *
165
     * @return $this
166
     * @throws \InvalidArgumentException
167
     */
168
    protected function setLocation()
169
    {
170
        if (!isset($this->job)) {
171
            throw new \InvalidArgumentException('cannot create a viewModel for Templates without aa $job');
172
        }
173
        $location = $this->job->getLocation();
174
        $this->container['location'] = isset($location)?$location:'';
175
        return $this;
176
    }
177
178
    /**
179
     * Sets the company description of a job. Use the description of an organization as default
180
     *
181
     * @return $this
182
     * @throws \InvalidArgumentException
183
     */
184
    protected function setDescription()
185
    {
186
        if (!isset($this->job)) {
187
            throw new \InvalidArgumentException('cannot create a viewModel for Templates without a $job');
188
        }
189
190
        if (empty($this->job->templateValues->description) && isset($this->job->organization)) {
0 ignored issues
show
Documentation introduced by
The property $templateValues is declared protected in Jobs\Entity\Job. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property $organization is declared protected in Jobs\Entity\Job. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property $description is declared protected in Jobs\Entity\TemplateValues. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
191
            $this->job->templateValues->description = $this->job->organization->description;
0 ignored issues
show
Documentation introduced by
The property $templateValues is declared protected in Jobs\Entity\Job. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property $organization is declared protected in Jobs\Entity\Job. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
Accessing description on the interface Organizations\Entity\OrganizationInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
Documentation introduced by
The property $description is declared protected in Jobs\Entity\TemplateValues. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
192
        }
193
        $description = $this->job->templateValues->description;
0 ignored issues
show
Documentation introduced by
The property $templateValues is declared protected in Jobs\Entity\Job. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property $description is declared protected in Jobs\Entity\TemplateValues. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
194
195
        $this->container['description'] = isset($description)?$description:'';
196
        return $this;
197
    }
198
199
    /**
200
     * Sets the organizations contact address
201
     *
202
     * @return $this
203
     * @throws \InvalidArgumentException
204
     */
205
    protected function setOrganizationInfo()
206
    {
207
        if (!isset($this->job)) {
208
            throw new \InvalidArgumentException('cannot create a viewModel for Templates without a $job');
209
        }
210
        $organizationName = '';
0 ignored issues
show
Unused Code introduced by
$organizationName is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
211
        $organizationStreet = '';
0 ignored issues
show
Unused Code introduced by
$organizationStreet is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
212
        $organizationPostalCode = '';
0 ignored issues
show
Unused Code introduced by
$organizationPostalCode is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
213
        $organizationPostalCity = '';
0 ignored issues
show
Unused Code introduced by
$organizationPostalCity is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
214
        $organization = $this->job->organization;
0 ignored issues
show
Documentation introduced by
The property $organization is declared protected in Jobs\Entity\Job. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
215
        $user = $this->job->getUser();
216
217
        if (isset($organization)) {
218
            $organizationName = $organization->organizationName->name;
0 ignored issues
show
Bug introduced by
Accessing organizationName on the interface Organizations\Entity\OrganizationInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
219
            $organizationStreet = $organization->contact->street.' '.$organization->contact->houseNumber;
0 ignored issues
show
Bug introduced by
Accessing contact on the interface Organizations\Entity\OrganizationInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
220
            $organizationPostalCode = $organization->contact->postalcode;
0 ignored issues
show
Bug introduced by
Accessing contact on the interface Organizations\Entity\OrganizationInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
221
            $organizationPostalCity = $organization->contact->city;
0 ignored issues
show
Bug introduced by
Accessing contact on the interface Organizations\Entity\OrganizationInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
222
            $organizationPhone = $organization->contact->phone;
0 ignored issues
show
Bug introduced by
Accessing contact on the interface Organizations\Entity\OrganizationInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
223
            $organizationFax = $organization->contact->fax;
0 ignored issues
show
Bug introduced by
Accessing contact on the interface Organizations\Entity\OrganizationInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
224
        } else {
225
            $organizationName =
226
            $organizationStreet =
227
            $organizationPostalCode =
228
            $organizationPostalCity =
229
            $organizationPhone =
230
            $organizationFax = '';
231
        }
232
        $this->container['contactEmail'] = $user ? $user->getInfo()->getEmail() : '';
233
        $this->container['organizationName'] = $organizationName;
234
        $this->container['street'] = $organizationStreet;
235
        $this->container['postalCode'] = $organizationPostalCode;
236
        $this->container['city'] = $organizationPostalCity;
237
        $this->container['phone'] = $organizationPhone;
238
        $this->container['fax'] = $organizationFax;
239
240
        if (isset($organization) && isset($organization->image) && $organization->image->uri) {
0 ignored issues
show
Bug introduced by
Accessing image on the interface Organizations\Entity\OrganizationInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
241
            $this->container['uriLogo'] = $this->makeAbsolutePath($organization->image->uri);
0 ignored issues
show
Bug introduced by
Accessing image on the interface Organizations\Entity\OrganizationInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
242
        } else {
243
            $this->container['uriLogo'] = $this->makeAbsolutePath($this->config->default_logo);
244
        }
245
        return $this;
246
    }
247
248
    /**
249
     * Sets the default values of an organizations job template
250
     *
251
     * @return $this
252
     * @throws \InvalidArgumentException
253
     */
254
    protected function setTemplateDefaultValues()
255
    {
256
        if (!isset($this->job)) {
257
            throw new \InvalidArgumentException('cannot create a viewModel for Templates without a $job');
258
        }
259
        $labelQualifications='';
260
        $labelBenefits='';
261
        $labelRequirements='';
262
263
        $organization = $this->job->organization;
0 ignored issues
show
Documentation introduced by
The property $organization is declared protected in Jobs\Entity\Job. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
264
        if (isset($organization)) {
265
            $labelRequirements = $organization->getTemplate()->getLabelRequirements();
266
            $labelQualifications = $organization->getTemplate()->getLabelQualifications();
267
            $labelBenefits = $organization->getTemplate()->getLabelBenefits();
268
        }
269
        $this->container['labelRequirements'] = $labelRequirements;
270
        $this->container['labelQualifications'] = $labelQualifications;
271
        $this->container['labelBenefits'] = $labelBenefits;
272
273
        return $this;
274
    }
275
276
    /**
277
     * Sets the template
278
     *
279
     * @return $this
280
     */
281
    protected function setTemplate()
282
    {
283
        $this->container['templateName'] = $this->job->template;
0 ignored issues
show
Documentation introduced by
The property $template is declared protected in Jobs\Entity\Job. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
284
        return $this;
285
    }
286
287
    /**
288
     * combines two helper
289
     *
290
     * @param $path
291
     * @return mixed
292
     */
293
    protected function makeAbsolutePath($path)
294
    {
295
        $path = $this->serverUrlHelper->__invoke($this->basePathHelper->__invoke($path));
296
        return $path;
297
    }
298
}
299