Issues (9)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Client/DataTransformer.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * YAWIK Stackoverflow API
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2016 - 2017 Cross Solution <http://cross-solution.de>
8
 */
9
  
10
/** */
11
namespace StackoverflowApi\Client;
12
13
use Core\Entity\Collection\ArrayCollection;
14
use Jobs\Entity\CoordinatesInterface;
15
use Jobs\Entity\JobInterface;
16
use Jobs\Entity\Location;
17
use Jobs\View\Helper\ApplyUrl;
18
use Organizations\ImageFileCache\Manager as ImageManager;
19
use StackoverflowApi\Utils\XmlBuilder;
20
use Zend\View\Helper\ServerUrl;
21
22
/**
23
 * Transformer for converting a Yawik Job to Stackoverflow XML
24
 * 
25
 * @author Mathias Gelhausen <[email protected]>
26
 * @todo write test
27
 * @since 0.1.0
28
 */
29
class DataTransformer 
30
{
31
32
    /**
33
     * Url helper for the apply link.
34
     *
35
     * @var ApplyUrl
36
     */
37
    protected $applyUrlHelper;
38
39
    /**
40
     * Server url view Helper
41
     *
42
     * @var ServerUrl
43
     */
44
    protected $serverUrlHelper;
45
46
    /**
47
     * Organization Image File Cache Manager
48
     *
49
     * @var ImageManager
50
     */
51
    protected $organizationImageManager;
52
53
    /**
54
     *
55
     *
56
     * @var JobDescriptionFilter
57
     */
58
    protected $descriptionFilter;
59
60
    /**
61
     * @param ApplyUrl $applyUrlHelper
62
     *
63
     * @return self
64
     */
65
    public function setApplyUrlHelper($applyUrlHelper)
66
    {
67
        $this->applyUrlHelper = $applyUrlHelper;
68
69
        return $this;
70
    }
71
72
    /**
73
     * @return ApplyUrl
74
     */
75
    public function getApplyUrlHelper()
76
    {
77
        return $this->applyUrlHelper;
78
    }
79
80
    /**
81
     * @param \Organizations\ImageFileCache\Manager $organizationImageManager
82
     *
83
     * @return self
84
     */
85
    public function setOrganizationImageManager($organizationImageManager)
86
    {
87
        $this->organizationImageManager = $organizationImageManager;
88
89
        return $this;
90
    }
91
92
    /**
93
     * @return \Organizations\ImageFileCache\Manager
94
     */
95
    public function getOrganizationImageManager()
96
    {
97
        return $this->organizationImageManager;
98
    }
99
100
    /**
101
     * @param \Zend\View\Helper\ServerUrl $serverUrlHelper
102
     *
103
     * @return self
104
     */
105
    public function setServerUrlHelper($serverUrlHelper)
106
    {
107
        $this->serverUrlHelper = $serverUrlHelper;
108
109
        return $this;
110
    }
111
112
    /**
113
     * @return \Zend\View\Helper\ServerUrl
114
     */
115
    public function getServerUrlHelper()
116
    {
117
        return $this->serverUrlHelper;
118
    }
119
120
    /**
121
     * @return JobDescriptionFilter
122
     */
123
    public function getDescriptionFilter()
124
    {
125
        if (!$this->descriptionFilter) {
126
            $this->descriptionFilter = new JobDescriptionFilter();
127
        }
128
        
129
        return $this->descriptionFilter;
130
    }
131
132
    /**
133
     * @param JobDescriptionFilter $descriptionFilter
134
     *
135
     * @return self
136
     */
137
    public function setDescriptionFilter($descriptionFilter)
138
    {
139
        $this->descriptionFilter = $descriptionFilter;
140
141
        return $this;
142
    }
143
144
145
146
147
    /**
148
     * Transform a job to stackoverflow XML
149
     *
150
     * @param JobInterface $job
151
     * @param array        $options
152
     *
153
     * @return string
154
     */
155
    public function transform(JobInterface $job, $options = [])
156
    {
157
        $applyUrl = $this->getApplyUrlHelper();
158
        $serverUrl = $this->getServerUrlHelper();
159
        $imageManager = $this->getOrganizationImageManager();
160
161
        $jobSpec = [
162
            'action' => isset($options['action']) ? $options['action'] : 'post',
163
            //'test' => 'true',
164
165
        ];
166
167
        if (isset($options['externalId'])) {
168
            $jobSpec['jobid'] = $options['externalId'];
169
        }
170
171
        $jobSpec[':title'] = $job->getTitle();
172
        $jobSpec[':company'] = $job->getOrganization()->getOrganizationName()->getName();
173
        $jobSpec[':companyurl'] = $job->getOrganization()->getContact()->getWebsite() ?: '';
174
175
        if (($image = $job->getOrganization()->getImage()) && $serverUrl && $imageManager) {
176
            $imageUri = $imageManager->getUri($image);
177
            $jobSpec['logourl'] = $serverUrl($imageUri);
178
        }
179
180
        if ($companyDesc = $job->getOrganization()->getDescription()) {
181
            $jobSpec[':aboutcompany'] = $companyDesc;
182
        }
183
184
        $jobSpec['vendorid'] = $job->getId();
185
186
        if (!empty($options['applyUrl'])) {
187
            $jobSpec['howtoapply'] = $options['applyUrl'];
188
        } else if ($contactEmail = $job->getContactEmail()) {
189
            $jobSpec['howtoapply'] = $contactEmail;
190
        } else {
191
            $atsMode = $job->getAtsMode();
192
            if ($atsMode->isDisabled()) {
193
                $jobSpec['howtoapply'] = 'postalisch';
194
            } else if ($atsMode->isEmail()) {
195
                $jobSpec['howtoapply'] = $atsMode->getEmail();
196
            } else if ($atsMode->isUri()) {
197
                $jobSpec['howtoapply'] = $atsMode->getUri();
198
            } else if (is_callable($applyUrl) && $serverUrl) {
199
                $jobSpec['howtoapply'] = $serverUrl($applyUrl($job, ['linkOnly' => true, 'absolute' => true]));
200
            } else {
201
                $jobSpec['howtoapply'] =  'postalisch';
202
            }
203
        }
204
205
206
207
        /* Location override by additional data */
208
        if (isset($options['location'])) {
209
            $location = new Location($options['location']);
210
            $locations = new ArrayCollection([$location]);
211
        } else {
212
            $locations = $job->getLocations();
213
        }
214
215
        if ($locations->count()) {
216
            $loc = [];
217
218
            foreach ($locations as $location) {
219
                /* \Jobs\Entity\Location $location */
220
                $tmpLoc = [];
221
                $coords = $location->getCoordinates();
222
                $postalCode = $location->getPostalCode();
223
                $city = $location->getCity();
224
                $country = $location->getCountry();
225
                $region = $location->getRegion();
226
227
                $str = '';
228
                if ($postalCode) { $str .= $postalCode . ' '; }
229
                if ($city) { $str .= $city; }
230
                if ($region) { $str .= ', ' . $region; }
231
                if ($country) { $str .= ', ' . $country; }
232
233
234
                /*
235
                 * see https://talent.stackoverflow.com/de/api/doc
236
                 * Value of location tag should only be the city name.
237
                 * Additional address information must be in the "address" attribute
238
                 */
239
                $tmpLoc['_text'] = $city;
240
                if ($str != $city) { $tmpLoc['@address'] = $str; }
241
                if ($coords) {
242
                    $coords = $coords->getCoordinates();
243
                    $tmpLoc['@lon'] = str_replace(',', '.', (string) $coords[0]);
244
                    $tmpLoc['@lat'] = str_replace(',', '.', (string) $coords[1]);
245
                }
246
247
                $loc[] = $tmpLoc;
248
            }
249
250
            $jobSpec['locations']['location'] = $loc;
251
        }
252
253
        foreach (['topspot', 'featured', 'remote', 'relocation', 'visasponsorship', 'sysadmin'] as $boolOpt) {
254
            if (isset($options[$boolOpt])) {
255
                $jobSpec[$boolOpt] = $options[$boolOpt] ? 'true' : 'false';
256
            }
257
        }
258
259
        foreach (['length', 'coupon', 'pixel'] as $strOpt) {
260
            if (isset($options[$strOpt])) {
261
                $jobSpec[$strOpt] = $options[$strOpt];
262
            }
263
        }
264
265
        $link = $job->getLink();
266
        $jobSpec[':description'] = $link ? $this->getDescriptionFilter()->filter($link) : '<p></p>';
267
268
        if ($requirements = $job->getTemplateValues()->getRequirements()) {
269
            $jobSpec[':requirements'] = $requirements;
270
        }
271
272
        $tags = [];
273 View Code Duplication
        if (isset($options['keywords']) && is_array($options['keyword'])) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
274
            foreach ($options['keywords'] as $keyword) {
275
                $tags[] = ['tag' => $keyword];
276
            }
277
        } else {
278
            $tags[] = ['tag' => 'none'];
279
        }
280
        $jobSpec['tags'] = $tags;
281
282 View Code Duplication
        if (isset($options['advertisingregions']) && is_array($options['advertisingregions'])) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
283
            $regions = [];
284
            foreach ($options['advertisingregions'] as $adreg) {
285
                $regions[] = ['regioncode' => $adreg];
286
            }
287
            $jobSpec['advertisingregions'] = $regions;
288
        }
289
290 View Code Duplication
        if (isset($options['advertisingcountries']) && is_array($options['advertisingcountries'])) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
291
            $countries = [];
292
            foreach ($options['advertisingcountries'] as $adcountry) {
293
                $countries[] = ['regioncode' => $adcountry];
294
            }
295
            $jobSpec['advertisingcountrycodes'] = $countries;
296
        }
297
298
299
        return XmlBuilder::createXml(['job' => $jobSpec]);
300
    }
301
}
302