PDFUploadField   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 39
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 24 2
1
<?php
2
3
/**
4
 * allow a pdf to be uploaded...
5
 *
6
 * Usage:
7
 *     $field = PDFUploadField::create(
8
 *         "ReportField",
9
 *         "Title",
10
 *         null,
11
 *         "folder-name"
12
 *     );
13
 */
14
class PDFUploadField extends UploadField
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
15
{
16
    private static $pdf_folder_name = "pdfs";
0 ignored issues
show
Unused Code introduced by
The property $pdf_folder_name is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
17
    /**
18
     * @param string  $name
19
     * @param string  $title
20
     * @param SS_List $items If no items are defined, the field will try to auto-detect an existing relation on
0 ignored issues
show
Documentation introduced by
Should the type for parameter $items not be null|SS_List?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
21
     *
22
     *                       @link $record}, with the same name as the field name.
23
     *
24
     * @param string $folderName
25
     *
26
     * @return ReportUploadField
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
27
     */
28
    public function __construct(
29
        $name,
30
        $title,
31
        SS_List $items = null,
32
        $folderName = ""
33
    ) {
34
        parent::__construct(
35
            $name,
36
            $title,
37
            $items
38
        );
39
        $this->setRightTitle('Only PDF files are accepted.');
40
        //create folder
41
        if (!$folderName) {
42
            $folderName = Config::inst()->get('PDFUploadField', 'pdf_folder_name');
43
        }
44
        Folder::find_or_make(Director::baseFolder()."/assets/".$folderName);
45
        //set folder
46
        $this->setFolderName($folderName);
47
        $this->setAllowedExtensions(array('pdf'));
48
        $this->setAllowedMaxFileNumber(1);
49
50
        return $this;
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
51
    }
52
}
53