Completed
Pull Request — master (#168)
by Franco
02:23
created

code/cms/DocumentHtmlEditorFieldToolbar.php (4 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
 * Extends the original toolbar with document picking capability - modified lines are commented.
4
 */
5
class DocumentHtmlEditorFieldToolbar extends Extension
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...
6
{
7
    public function updateLinkForm(Form $form)
8
    {
9
        $linkType = null;
10
        $fieldList = null;
11
        $fields = $form->Fields();//->fieldByName('Heading');
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
12
        foreach ($fields as $field) {
0 ignored issues
show
The expression $fields of type object<FieldList>|null is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
13
            $linkType = ($field->fieldByName('LinkType'));
14
            $fieldList = $field;
15
            if ($linkType) {
16
                break;
17
            }   //break once we have the object
18
        }
19
20
        $source = $linkType->getSource();
21
        $source['document'] = 'Download a document';
22
        $linkType->setSource($source);
23
24
        $addExistingField = new DMSDocumentAddExistingField('AddExisting', 'Add Existing');
25
        $addExistingField->setForm($form);
26
        $addExistingField->setUseFieldClass(false);
27
        $fieldList->insertAfter($addExistingField, 'Description');
28
29
//		Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/behaviour/behaviour.js");
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
30
//		Requirements::javascript(SAPPHIRE_DIR . "/javascript/tiny_mce_improvements.js");
31
//
32
//		// create additional field, rebase to 'documents' directory
33
//		$documents = new TreeDropdownField('document', 'Document', 'File', 'ID', 'DocumentDropdownTitle', true);
34
//		$documents->setSearchFunction(array($this, 'documentSearchCallback'));
35
//		$baseFolder = Folder::find_or_make(Document::$directory);
36
//		$documents->setTreeBaseID($baseFolder->ID);
37
38
39
        //return $form;
40
    }
41
}
42