FileUpload::postFileUpload()   B
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 29
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 29
ccs 0
cts 29
cp 0
rs 8.5806
cc 4
eloc 26
nc 4
nop 1
crap 20
1
<?php
2
3
namespace SpeckCatalog\Event;
4
5
class FileUpload
6
{
7
    public function preFileUpload($e)
8
    {
9
        $formData = $e->getParam('params');
10
        $getter = 'get' . ucfirst($formData['file_type']) . 'Upload';
11
12
        $catalogOptions = $this->getServiceManager()->get('speckcatalog_module_options');
0 ignored issues
show
Bug introduced by
The method getServiceManager() does not seem to exist on object<SpeckCatalog\Event\FileUpload>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
13
14
        if ($formData['file_type'] === 'productDocument') {
15
            $e->getParam('options')->setAllowedFileTypes(array('pdf' => 'pdf'));
16
            $e->getParam('options')->setUseMin(false);
17
            $e->getParam('options')->setUseMax(false);
18
        }
19
20
        $appRoot = __DIR__ . '/../..';
21
        $path = $appRoot . $catalogOptions->$getter();
22
        $e->getParam('options')->setDestination($path);
23
    }
24
25
    public function postFileUpload($e)
26
    {
27
        $params = $e->getParams();
28
        switch ($params['params']['file_type']) {
29
            case 'productImage':
30
                $imageService = $this->getServiceManager()->get('speckcatalog_product_image_service');
0 ignored issues
show
Bug introduced by
The method getServiceManager() does not seem to exist on object<SpeckCatalog\Event\FileUpload>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
31
                $image = $imageService->getEntity();
32
                $image->setProductId($params['params']['product_id'])
33
                    ->setFileName($params['fileName']);
34
                $imageService->persist($image);
35
                break;
36
            case 'productDocument':
37
                $documentService = $this->getServiceManager()->get('speckcatalog_document_service');
0 ignored issues
show
Bug introduced by
The method getServiceManager() does not seem to exist on object<SpeckCatalog\Event\FileUpload>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
                $document = $documentService->getEntity();
39
                $document->setProductId($params['params']['product_id'])
40
                    ->setFileName($params['fileName']);
41
                $documentService->persist($document);
42
                break;
43
            case 'optionImage':
44
                $imageService = $this->getServiceManager()->get('speckcatalog_option_image_service');
0 ignored issues
show
Bug introduced by
The method getServiceManager() does not seem to exist on object<SpeckCatalog\Event\FileUpload>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
45
                $image = $imageService->getEntity();
46
                $image->setOptionId($params['params']['option_id'])
47
                    ->setFileName($params['fileName']);
48
                $imageService->persist($image);
49
                break;
50
            default:
51
                throw new \Exception('no handler for file type - ' . $params['params']['file_type']);
52
        }
53
    }
54
}
55