Upload::execute()   A
last analyzed

Complexity

Conditions 2
Paths 3

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 16
rs 9.9
c 0
b 0
f 0
cc 2
nc 3
nop 0
1
<?php
2
/**
3
 * MagePrince
4
 *
5
 * NOTICE OF LICENSE
6
 *
7
 * This source file is subject to the mageprince.com license that is
8
 * available through the world-wide-web at this URL:
9
 * https://mageprince.com/end-user-license-agreement
10
 *
11
 * DISCLAIMER
12
 *
13
 * Do not edit or add to this file if you wish to upgrade this extension to newer
14
 * version in the future.
15
 *
16
 * @category    MagePrince
17
 * @package     Mageprince_Faq
18
 * @copyright   Copyright (c) MagePrince (https://mageprince.com/)
19
 * @license     https://mageprince.com/end-user-license-agreement
20
 */
21
22
namespace Mageprince\Faq\Controller\Adminhtml\FaqGroup;
23
24
use Magento\Backend\App\Action;
0 ignored issues
show
Bug introduced by
The type Magento\Backend\App\Action was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
use Magento\Framework\Controller\ResultFactory;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Controller\ResultFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
26
use Magento\Framework\Controller\ResultInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Controller\ResultInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
use Mageprince\Faq\Model\ImageUploader;
28
29
class Upload extends FaqGroup
30
{
31
    /**
32
     * @var ImageUploader
33
     */
34
    public $imageUploader;
35
36
    /**
37
     * Upload constructor.
38
     *
39
     * @param Action\Context $context
40
     * @param ImageUploader $imageUploader
41
     */
42
    public function __construct(
43
        Action\Context $context,
0 ignored issues
show
Bug introduced by
The type Magento\Backend\App\Action\Context was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
44
        ImageUploader $imageUploader
45
    ) {
46
        parent::__construct($context);
47
        $this->imageUploader = $imageUploader;
48
    }
49
50
    /**
51
     * Upload file controller action
52
     *
53
     * @return ResultInterface
54
     */
55
    public function execute()
56
    {
57
        try {
58
            $result = $this->imageUploader->saveFileToTmpDir('icon');
59
60
            $result['cookie'] = [
61
                'name' => $this->_getSession()->getName(),
62
                'value' => $this->_getSession()->getSessionId(),
63
                'lifetime' => $this->_getSession()->getCookieLifetime(),
64
                'path' => $this->_getSession()->getCookiePath(),
65
                'domain' => $this->_getSession()->getCookieDomain(),
66
            ];
67
        } catch (\Exception $e) {
68
            $result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()];
69
        }
70
        return $this->resultFactory->create(ResultFactory::TYPE_JSON)->setData($result);
71
    }
72
}
73