src/Shop/Views/OrderAttachment.php

Summary

Maintainability
D
2 days
Test Coverage

Method upload has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function upload($request, $match)
    {
        $order = null;
        if (isset($match['secureId'])) {
            $order = Shop_Shortcuts_GetObjectBySecureIdOr404('Shop_Order', $match['secureId']);
Severity: Minor
Found in src/Shop/Views/OrderAttachment.php - About 1 hr to fix

    Method create has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function create($request, $match)
        {
            $order = null;
            if (isset($match['secureId'])) {
                $order = Shop_Shortcuts_GetObjectBySecureIdOr404('Shop_Order', $match['secureId']);
    Severity: Minor
    Found in src/Shop/Views/OrderAttachment.php - About 1 hr to fix

      Function upload has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          public function upload($request, $match)
          {
              $order = null;
              if (isset($match['secureId'])) {
                  $order = Shop_Shortcuts_GetObjectBySecureIdOr404('Shop_Order', $match['secureId']);
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.php - About 35 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function create has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          public function create($request, $match)
          {
              $order = null;
              if (isset($match['secureId'])) {
                  $order = Shop_Shortcuts_GetObjectBySecureIdOr404('Shop_Order', $match['secureId']);
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.php - About 35 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function download has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          public function download($request, $match)
          {
              // Check order
              $order = null;
              if (isset($match['secureId'])) {
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.php - About 25 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

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

                  throw new Pluf_Exception_DoesNotExist('given attachment is not blong to given order');
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.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 31.
      Open

          public function create($request, $match)
          {
              $order = null;
              if (isset($match['secureId'])) {
                  $order = Shop_Shortcuts_GetObjectBySecureIdOr404('Shop_Order', $match['secureId']);
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.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

      Missing class import via use statement (line '184', column '25').
      Open

                  $form = new Shop_Form_OrderAttachmentUpdate(array_merge($request->REQUEST, $request->FILES), $extra);
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.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 '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/Shop/Views/OrderAttachment.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 '144', column '23').
      Open

                  throw new Pluf_Exception_BadRequest('attachment id required');
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.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 '52', column '28').
      Open

                      return new Pluf_Exception_Unauthorized('You are not allowed to do this action.');
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.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 '151', column '25').
      Open

              $response = new Pluf_HTTP_Response_File($attachment->getAbsloutPath(), $attachment->mime_type);
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.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 '39', column '21').
      Open

              $form = new Shop_Form_OrderAttachmentUpdate(array_merge($request->REQUEST, $request->FILES), $extra);
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.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 '92', column '28').
      Open

                      return new Pluf_Exception_Unauthorized('You are not allowed to do this action.');
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.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 '171', column '28').
      Open

                      return new Pluf_Exception_Unauthorized('You are not allowed to do this action.');
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.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 '72', column '28').
      Open

                      return new Pluf_Exception_Unauthorized('You are not allowed to do this action.');
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.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 '177', column '23').
      Open

                  throw new Pluf_Exception_DoesNotExist('given attachment is not blong to given order');
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.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 '21', column '28').
      Open

                      return new Pluf_Exception_Unauthorized('You are not allowed to do this action.');
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.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 '139', column '28').
      Open

                      return new Pluf_Exception_Unauthorized('You are not allowed to do this action.');
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.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 '112', column '28').
      Open

                      return new Pluf_Exception_Unauthorized('You are not allowed to do this action.');
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.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 'Shop_Precondition' in method 'get'.
      Open

                  if (! Shop_Precondition::canViewOrder($request, $order)) {
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.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 'Shop_Precondition' in method 'delete'.
      Open

                  if (! Shop_Precondition::canModifyOrder($request, $order)) {
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.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

      The method upload uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

              } else {
                  $order = Pluf_Shortcuts_GetObjectOr404('Shop_Order', $match['orderId']);
                  // Check access to order
                  if (! Shop_Precondition::canViewOrder($request, $order)) {
                      return new Pluf_Exception_Unauthorized('You are not allowed to do this action.');
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($flag) {
                  // one branch
              } else {
                  // another branch
              }
          }
      }

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

      Avoid using static access to class 'Shop_Precondition' in method 'update'.
      Open

                  if (! Shop_Precondition::canModifyOrder($request, $order)) {
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.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

      The method upload uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

              } else {
                  $myfile = fopen($attachment->getAbsloutPath(), "w") or die("Unable to open file!");
                  $entityBody = file_get_contents('php://input', 'r');
                  fwrite($myfile, $entityBody);
                  fclose($myfile);
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($flag) {
                  // one branch
              } else {
                  // another branch
              }
          }
      }

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

      The method get uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

              } else {
                  $order = Pluf_Shortcuts_GetObjectOr404('Shop_Order', $match['parentId']);
                  if (! Shop_Precondition::canViewOrder($request, $order)) {
                      return new Pluf_Exception_Unauthorized('You are not allowed to do this action.');
                  }
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($flag) {
                  // one branch
              } else {
                  // another branch
              }
          }
      }

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

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

              Pluf::loadFunction('Pluf_Shortcuts_GetObjectOr404');
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.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 'Shop_Precondition' in method 'create'.
      Open

                  if (!Shop_Precondition::canModifyOrder($request, $order)) {
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.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 'upload'.
      Open

              Pluf::loadFunction('Pluf_Shortcuts_GetObjectOr404');
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.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

      The method create uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

              } else {
                  $order = Pluf_Shortcuts_GetObjectOr404('Shop_Order', $match['parentId']);
                  if (!Shop_Precondition::canModifyOrder($request, $order)) {
                      return new Pluf_Exception_Unauthorized('You are not allowed to do this action.');
                  }
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($flag) {
                  // one branch
              } else {
                  // another branch
              }
          }
      }

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

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

              $attachment->file_path = Pluf::f('upload_path') . '/' . $request->tenant->id . '/shop-order-attachment';
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.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 'Shop_Precondition' in method 'find'.
      Open

                  if (! Shop_Precondition::canViewOrder($request, $order)) {
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.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 'Shop_Precondition' in method 'upload'.
      Open

                  if (! Shop_Precondition::canViewOrder($request, $order)) {
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.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

      The method update uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

              } else {
                  $order = Pluf_Shortcuts_GetObjectOr404('Shop_Order', $match['parentId']);
                  if (! Shop_Precondition::canModifyOrder($request, $order)) {
                      return new Pluf_Exception_Unauthorized('You are not allowed to do this action.');
                  }
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($flag) {
                  // one branch
              } else {
                  // another branch
              }
          }
      }

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

      The method find uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

              } else {
                  $order = Pluf_Shortcuts_GetObjectOr404('Shop_Order', $match['parentId']);
                  if (! Shop_Precondition::canViewOrder($request, $order)) {
                      return new Pluf_Exception_Unauthorized('You are not allowed to do this action.');
                  }
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($flag) {
                  // one branch
              } else {
                  // another branch
              }
          }
      }

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

      The method delete uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

              } else {
                  $order = Pluf_Shortcuts_GetObjectOr404('Shop_Order', $match['parentId']);
                  if (! Shop_Precondition::canModifyOrder($request, $order)) {
                      return new Pluf_Exception_Unauthorized('You are not allowed to do this action.');
                  }
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($flag) {
                  // one branch
              } else {
                  // another branch
              }
          }
      }

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

      The method download uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

              } else {
                  $order = Pluf_Shortcuts_GetObjectOr404('Shop_Order', $match['orderId']);
                  // Check access to order
                  if (! Shop_Precondition::canViewOrder($request, $order)) {
                      return new Pluf_Exception_Unauthorized('You are not allowed to do this action.');
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($flag) {
                  // one branch
              } else {
                  // another branch
              }
          }
      }

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

      Avoid using static access to class 'Shop_Precondition' in method 'download'.
      Open

                  if (! Shop_Precondition::canViewOrder($request, $order)) {
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.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

      Define a constant instead of duplicating this literal "model" 7 times.
      Open

                  'model' => 'Shop_OrderAttachment',
      Severity: Critical
      Found in src/Shop/Views/OrderAttachment.php by sonar-php

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "You are not allowed to do this action." 7 times.
      Open

                      return new Pluf_Exception_Unauthorized('You are not allowed to do this action.');
      Severity: Critical
      Found in src/Shop/Views/OrderAttachment.php by sonar-php

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "secureId" 14 times.
      Open

              if (isset($match['secureId'])) {
      Severity: Critical
      Found in src/Shop/Views/OrderAttachment.php by sonar-php

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Merge this if statement with the enclosing one.
      Open

                  if (false == @mkdir($attachment->file_path, 0777, true)) {

      Merging collapsible if statements increases the code's readability.

      Noncompliant Code Example

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

      Compliant Solution

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

      Define a constant instead of duplicating this literal "parent" 5 times.
      Open

                  'parent' => 'Shop_Order',
      Severity: Critical
      Found in src/Shop/Views/OrderAttachment.php by sonar-php

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "Shop_OrderAttachment" 7 times.
      Open

                  'model' => 'Shop_OrderAttachment',
      Severity: Critical
      Found in src/Shop/Views/OrderAttachment.php by sonar-php

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "parentKey" 5 times.
      Open

                  'parentKey' => 'order_id'
      Severity: Critical
      Found in src/Shop/Views/OrderAttachment.php by sonar-php

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "parentId" 10 times.
      Open

                  $match['parentId'] = $order->id;
      Severity: Critical
      Found in src/Shop/Views/OrderAttachment.php by sonar-php

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "order_id" 5 times.
      Open

                  'parentKey' => 'order_id'
      Severity: Critical
      Found in src/Shop/Views/OrderAttachment.php by sonar-php

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "modelId" 3 times.
      Open

              if (! array_key_exists('modelId', $match)) {
      Severity: Critical
      Found in src/Shop/Views/OrderAttachment.php by sonar-php

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "Shop_Order" 19 times.
      Open

                  $order = Shop_Shortcuts_GetObjectBySecureIdOr404('Shop_Order', $match['secureId']);
      Severity: Critical
      Found in src/Shop/Views/OrderAttachment.php by sonar-php

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      The method upload() contains an exit expression.
      Open

                  $myfile = fopen($attachment->getAbsloutPath(), "w") or die("Unable to open file!");
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.php by phpmd

      ExitExpression

      Since: 0.2

      An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.

      Example

      class Foo {
          public function bar($param)  {
              if ($param === 42) {
                  exit(23);
              }
          }
      }

      Source https://phpmd.org/rules/design.html#exitexpression

      Similar blocks of code found in 4 locations. Consider refactoring.
      Open

          public function get($request, $match)
          {
              $order = null;
              if (isset($match['secureId'])) {
                  $order = Shop_Shortcuts_GetObjectBySecureIdOr404('Shop_Order', $match['secureId']);
      Severity: Major
      Found in src/Shop/Views/OrderAttachment.php and 3 other locations - About 3 hrs to fix
      src/Shop/Views/OrderAttachment.php on lines 43..61
      src/Shop/Views/OrderAttachment.php on lines 83..101
      src/Shop/Views/OrderAttachment.php on lines 103..121

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 156.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 4 locations. Consider refactoring.
      Open

          public function find($request, $match)
          {
              $order = null;
              if (isset($match['secureId'])) {
                  $order = Shop_Shortcuts_GetObjectBySecureIdOr404('Shop_Order', $match['secureId']);
      Severity: Major
      Found in src/Shop/Views/OrderAttachment.php and 3 other locations - About 3 hrs to fix
      src/Shop/Views/OrderAttachment.php on lines 63..81
      src/Shop/Views/OrderAttachment.php on lines 83..101
      src/Shop/Views/OrderAttachment.php on lines 103..121

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 156.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 4 locations. Consider refactoring.
      Open

          public function delete($request, $match)
          {
              $order = null;
              if (isset($match['secureId'])) {
                  $order = Shop_Shortcuts_GetObjectBySecureIdOr404('Shop_Order', $match['secureId']);
      Severity: Major
      Found in src/Shop/Views/OrderAttachment.php and 3 other locations - About 3 hrs to fix
      src/Shop/Views/OrderAttachment.php on lines 43..61
      src/Shop/Views/OrderAttachment.php on lines 63..81
      src/Shop/Views/OrderAttachment.php on lines 83..101

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 156.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 4 locations. Consider refactoring.
      Open

          public function update($request, $match)
          {
              $order = null;
              if (isset($match['secureId'])) {
                  $order = Shop_Shortcuts_GetObjectBySecureIdOr404('Shop_Order', $match['secureId']);
      Severity: Major
      Found in src/Shop/Views/OrderAttachment.php and 3 other locations - About 3 hrs to fix
      src/Shop/Views/OrderAttachment.php on lines 43..61
      src/Shop/Views/OrderAttachment.php on lines 63..81
      src/Shop/Views/OrderAttachment.php on lines 103..121

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 156.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

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

      class Shop_Views_OrderAttachment extends Pluf_Views

      The class Shop_Views_OrderAttachment is not named in CamelCase.
      Open

      class Shop_Views_OrderAttachment extends Pluf_Views
      {
      
          /**
           *
      Severity: Minor
      Found in src/Shop/Views/OrderAttachment.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

      The closing brace for the class must go on the next line after the body
      Open

      }

      Expected 1 blank line at end of file; 2 found
      Open

      }

      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.');

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

      class Shop_Views_OrderAttachment extends Pluf_Views

      There are no issues that match your filters.

      Category
      Status