Issues (1)

src/controllers/ApplyController.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * Lever plugin for Craft CMS 3.x
4
 *
5
 * Craft + Lever.
6
 *
7
 * @link      https://workingconcept.com
8
 * @copyright Copyright (c) 2018 Working Concept Inc.
9
 */
10
11
namespace workingconcept\lever\controllers;
12
13
use workingconcept\lever\Lever;
14
use workingconcept\lever\models\LeverJobApplication;
15
use Craft;
16
use craft\web\Controller;
17
use yii\web\Response;
18
use yii\web\UploadedFile;
19
20
class ApplyController extends Controller
21
{
22
    // Public Properties
23
    // =========================================================================
24
25
    /**
26
     * @inheritdoc
27
     */
28
    public $allowAnonymous = true;
29
30
31
    // Public Methods
32
    // =========================================================================
33
34
    /**
35
     * Posts a job application.
36
     *
37
     * @return Response|null
38
     * @throws
39
     */
40
    public function actionIndex()
41
    {
42
        $this->requirePostRequest();
43
44
        $request = Craft::$app->getRequest();
45
46
        if ($jobId = $request->getParam('jobId'))
47
        {
48
            $resumeIncluded = ! empty($_FILES['resume']['tmp_name'])
49
                && ! empty($_FILES['resume']['name']);
50
51
            $application = new LeverJobApplication([
52
                'name'     => $request->getParam('name'),
53
                'email'    => $request->getParam('email'),
54
                'phone'    => $request->getParam('phone'),
55
                'org'      => $request->getParam('org'),
56
                'urls'     => $request->getParam('urls'),
57
                'comments' => $request->getParam('comments'),
58
                'ip'       => $request->getUserIP(),
59
                'silent'   => Lever::$plugin->getSettings()->applySilently,
60
                'source'   => Lever::$plugin->getSettings()->applicationSource,
61
            ]);
62
63
            if ($resumeIncluded)
64
            {
65
                $application->resume = UploadedFile::getInstanceByName('resume');
66
            }
67
68
            if (Lever::$plugin->api->applyForJob($jobId, $application))
69
            {
70
                if ($request->getAcceptsJson())
71
                {
72
                    return $this->asJson(['success' => true]);
73
                }
74
75
                Craft::$app->getSession()->setNotice('Application submitted.');
76
77
                return $this->redirectToPostedUrl();
78
            }
79
80
            if ($request->getAcceptsJson())
81
            {
82
                return $this->asJson(['errors' => $application->getErrors()]);
83
            }
84
85
            Craft::$app->getSession()->setError(Craft::t(
86
                'lever',
87
                'There was a problem with the application. Please check the form and try again!'
88
            ));
89
90
            Craft::$app->getUrlManager()->setRouteParams([
91
                'variables' => ['application' => $application]
92
            ]);
93
94
            return null;
95
        }
96
97
        Craft::$app->getSession()->setError(Craft::t(
98
            'lever',
99
            'Job ID missing.'
100
        ));
101
102
        return null;
103
    }
104
105
    /**
106
     * Capture a test post and save its data as a JSON file for troubleshooting.
107
     *
108
     * @return Response
109
     * @throws \yii\web\BadRequestHttpException
110
     */
111
    public function actionTest()
112
    {
113
        $this->requirePostRequest();
114
115
        if (Lever::$plugin->api->applyForJob(Craft::$app->getRequest()->getParam('jobId')))
0 ignored issues
show
The call to workingconcept\lever\ser...rService::applyForJob() has too few arguments starting with jobApplication. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

115
        if (Lever::$plugin->api->/** @scrutinizer ignore-call */ applyForJob(Craft::$app->getRequest()->getParam('jobId')))

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
116
        {
117
            file_put_contents('lever-application-test-' . time() . '.json', json_encode(Craft::$app->getRequest()->post()));
118
119
            return $this->asJson(Craft::$app->getRequest()->post());
120
        }
121
122
        return $this->asJson(Lever::$plugin->api->errors);
123
    }
124
}
125