Passed
Push — master ( 7c438c...2c13cb )
by Alex
01:26
created

SimpleStreamProvider   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 53
Duplicated Lines 71.7 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 3
Bugs 2 Features 0
Metric Value
wmc 10
c 3
b 2
f 0
lcom 0
cbo 1
dl 38
loc 53
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultStreamEditMediaUri() 7 7 2
A getReadStream2() 8 8 2
A getStreamContentType2() 0 7 2
A getStreamETag2() 12 12 2
A getReadStreamUri2() 11 12 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace POData\Providers\Stream;
4
5
use POData\OperationContext\IOperationContext;
6
use POData\Providers\Metadata\ResourceStreamInfo;
7
use POData\Providers\Metadata\ResourceType;
8
9
class SimpleStreamProvider implements IStreamProvider2
10
{
11 View Code Duplication
    public function getReadStream2($entity, ResourceStreamInfo $resourceStreamInfo = null, $eTag, $checkETagForEquality, IOperationContext $operationContext)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
12
    {
13
        if (null == $resourceStreamInfo) {
14
            return "stream for " . get_class($entity);
15
        }
16
        $name = $resourceStreamInfo->getName();
17
        return $entity->$name;
18
    }
19
20 View Code Duplication
    public function getDefaultStreamEditMediaUri($entity, ResourceType $resourceType, ResourceStreamInfo $resourceStreamInfo = null, IOperationContext $operationContext, $relativeUri = null)
0 ignored issues
show
Unused Code introduced by
The parameter $entity is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $resourceType is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $operationContext is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
    {
22
        if (null == $resourceStreamInfo) {
23
            return $relativeUri . '/$value';
24
        }
25
        return $relativeUri . '/' . $resourceStreamInfo->getName();
26
    }
27
28
    public function getStreamContentType2($entity, ResourceStreamInfo $resourceStreamInfo = null, IOperationContext $operationContext)
29
    {
30
        if (null == $resourceStreamInfo) {
31
            return "*/*";
32
        }
33
        return 'application/octet-stream';
34
    }
35
36 View Code Duplication
    public function getStreamETag2(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
        $entity,
38
        ResourceStreamInfo $resourceStreamInfo = null,
39
        IOperationContext $operationContext
40
    ) {
41
        if (null == $resourceStreamInfo) {
42
            return spl_object_hash($entity);
43
        }
44
        $name = $resourceStreamInfo->getName();
45
46
        return sha1($entity->$name);
47
    }
48
49 View Code Duplication
    public function getReadStreamUri2(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
        $entity,
51
        ResourceStreamInfo $resourceStreamInfo = null,
52
        IOperationContext $operationContext,
53
        $relativeUri = null
54
    ) {
55
        if (null == $resourceStreamInfo) {
56
            return $relativeUri . '/$value';
57
        }
58
        return $relativeUri . '/' . $resourceStreamInfo->getName();
59
        //let library creates default media url.
60
    }
61
}
62