Completed
Pull Request — master (#822)
by
unknown
19:08
created

TestService   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 31
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handleException() 0 8 3
A find() 0 12 2
1
<?php
2
namespace OCA\Calendar\Service;
3
4
use Exception;
5
6
use OCP\AppFramework\Db\DoesNotExistException;
7
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
8
9
use OCA\Calendar\Db\Test;
10
use OCA\Calendar\Db\TestMapper;
11
12
13
class TestService {
14
15
    private $mapper;
16
17
    public function __construct(TestMapper $mapper){
18
        $this->mapper = $mapper;
19
    }
20
21
22
    private function handleException ($e) {
23
        if ($e instanceof DoesNotExistException ||
0 ignored issues
show
Bug introduced by
The class OCP\AppFramework\Db\DoesNotExistException does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
24
            $e instanceof MultipleObjectsReturnedException) {
0 ignored issues
show
Bug introduced by
The class OCP\AppFramework\Db\Mult...bjectsReturnedException does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
25
            throw new NotFoundException($e->getMessage());
26
        } else {
27
            throw $e;
28
        }
29
    }
30
31
    public function find($id) {
32
        try {
33
            return $this->mapper->find($id);
34
35
        // in order to be able to plug in different storage backends like files
36
        // for instance it is a good idea to turn storage related exceptions
37
        // into service related exceptions so controllers and service users
38
        // have to deal with only one type of exception
39
        } catch(Exception $e) {
40
            $this->handleException($e);
41
        }
42
    }
43
}