src/ELearn/Form/PartCreate.php

Summary

Maintainability
A
0 mins
Test Coverage

Missing class import via use statement (line '37', column '27').
Open

                throw new Pluf_Form_Invalid('An error occured when creating the upload path. Please try to send the file again.');
Severity: Minor
Found in src/ELearn/Form/PartCreate.php by phpmd

MissingImport

Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

Example

function make() {
    return new \stdClass();
}

Source http://phpmd.org/rules/cleancode.html#MissingImport

Remove error control operator '@' on line 36.
Open

    function save($commit = true)
    {
        if (! $this->isValid()) {
            throw new Pluf_Exception_Form('cannot save the Part from an invalid form', $this);
        }
Severity: Minor
Found in src/ELearn/Form/PartCreate.php by phpmd

ErrorControlOperator

Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

Example

function foo($filePath) {
    $file = @fopen($filPath); // hides exceptions
    $key = @$array[$notExistingKey]; // assigns null to $key
}

Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

The method save has a boolean flag argument $commit, which is a certain sign of a Single Responsibility Principle violation.
Open

    function save($commit = true)
Severity: Minor
Found in src/ELearn/Form/PartCreate.php by phpmd

BooleanArgumentFlag

Since: 1.4.0

A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

Example

class Foo {
    public function bar($flag = true) {
    }
}

Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

Missing class import via use statement (line '29', column '23').
Open

            throw new Pluf_Exception_Form('cannot save the Part from an invalid form', $this);
Severity: Minor
Found in src/ELearn/Form/PartCreate.php by phpmd

MissingImport

Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

Example

function make() {
    return new \stdClass();
}

Source http://phpmd.org/rules/cleancode.html#MissingImport

Missing class import via use statement (line '32', column '21').
Open

        $part = new ELearn_Part();
Severity: Minor
Found in src/ELearn/Form/PartCreate.php by phpmd

MissingImport

Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

Example

function make() {
    return new \stdClass();
}

Source http://phpmd.org/rules/cleancode.html#MissingImport

Avoid using static access to class 'Pluf_Tenant' in method 'initFields'.
Open

        $this->tenant = Pluf_Tenant::current();
Severity: Minor
Found in src/ELearn/Form/PartCreate.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid using static access to class 'Pluf' in method 'save'.
Open

        $part->file_path = Pluf::f('upload_path') . '/' . $this->tenant->id . '/part';
Severity: Minor
Found in src/ELearn/Form/PartCreate.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Merge this if statement with the enclosing one.
Open

            if (false == @mkdir($part->file_path, 0777, true)) {
Severity: Major
Found in src/ELearn/Form/PartCreate.php by sonar-php

Merging collapsible if statements increases the code's readability.

Noncompliant Code Example

if (condition1) {
  if (condition2) {
    ...
  }
}

Compliant Solution

if (condition1 && condition2) {
  ...
}

Call to undeclared method \ELearn_Part::create
Open

            $part->create();
Severity: Critical
Found in src/ELearn/Form/PartCreate.php by phan

Reference to undeclared property \ELearn_Part->file_path
Open

        if (! is_dir($part->file_path)) {
Severity: Minor
Found in src/ELearn/Form/PartCreate.php by phan

Call to method current from undeclared class \Pluf_Tenant
Open

        $this->tenant = Pluf_Tenant::current();
Severity: Critical
Found in src/ELearn/Form/PartCreate.php by phan

Reference to undeclared property \ELearn_Part->file_path
Open

        $part->file_path = Pluf::f('upload_path') . '/' . $this->tenant->id . '/part';
Severity: Minor
Found in src/ELearn/Form/PartCreate.php by phan

Call to undeclared method \ELearn_Part::setFromFormData
Open

        $part->setFromFormData($this->cleaned_data);
Severity: Critical
Found in src/ELearn/Form/PartCreate.php by phan

Reference to undeclared property \ELearn_Form_PartCreate->cleaned_data
Open

        $part->setFromFormData($this->cleaned_data);
Severity: Minor
Found in src/ELearn/Form/PartCreate.php by phan

Call to method __construct from undeclared class \Pluf_Exception_Form
Open

            throw new Pluf_Exception_Form('cannot save the Part from an invalid form', $this);
Severity: Critical
Found in src/ELearn/Form/PartCreate.php by phan

Call to method f from undeclared class \Pluf
Open

        $part->file_path = Pluf::f('upload_path') . '/' . $this->tenant->id . '/part';
Severity: Critical
Found in src/ELearn/Form/PartCreate.php by phan

Call to undeclared method \ELearn_Form_PartCreate::isValid
Open

        if (! $this->isValid()) {
Severity: Critical
Found in src/ELearn/Form/PartCreate.php by phan

Reference to undeclared class \Pluf_Form_Model
Open

        parent::initFields($extra);
Severity: Critical
Found in src/ELearn/Form/PartCreate.php by phan

Call to method loadFunction from undeclared class \Pluf
Open

Pluf::loadFunction('ELearn_Shortcuts_CleanName');
Severity: Critical
Found in src/ELearn/Form/PartCreate.php by phan

Class extends undeclared class \Pluf_Form_Model
Open

class ELearn_Form_PartCreate extends Pluf_Form_Model
Severity: Critical
Found in src/ELearn/Form/PartCreate.php by phan

Reference to undeclared property \ELearn_Part->file_path
Open

            if (false == @mkdir($part->file_path, 0777, true)) {
Severity: Minor
Found in src/ELearn/Form/PartCreate.php by phan

Call to method __construct from undeclared class \Pluf_Form_Invalid
Open

                throw new Pluf_Form_Invalid('An error occured when creating the upload path. Please try to send the file again.');
Severity: Critical
Found in src/ELearn/Form/PartCreate.php by phan

Each class must be in a namespace of at least one level (a top-level vendor name)
Open

class ELearn_Form_PartCreate extends Pluf_Form_Model

A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 12 and the first side effect is on line 2.
Open

<?php

The class ELearn_Form_PartCreate is not named in CamelCase.
Open

class ELearn_Form_PartCreate extends Pluf_Form_Model
{

    public $tenant = null;

Severity: Minor
Found in src/ELearn/Form/PartCreate.php by phpmd

CamelCaseClassName

Since: 0.2

It is considered best practice to use the CamelCase notation to name classes.

Example

class class_name {
}

Source

Visibility must be declared on method "save"
Open

    function save($commit = true)

Line exceeds 120 characters; contains 130 characters
Open

                throw new Pluf_Form_Invalid('An error occured when creating the upload path. Please try to send the file again.');

Whitespace found at end of line
Open

 *        

Class name "ELearn_Form_PartCreate" is not in camel caps format
Open

class ELearn_Form_PartCreate extends Pluf_Form_Model

There are no issues that match your filters.

Category
Status