GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#1)
by Ema
03:02
created

Files   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 65
Duplicated Lines 15.38 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 5
dl 10
loc 65
ccs 0
cts 27
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B sendFile() 0 33 3
A getFileMetadata() 10 10 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
declare(strict_types=1);
4
5
namespace Pnz\MattermostClient\Api;
6
7
use Http\Message\MultipartStream\MultipartStreamBuilder;
8
use Pnz\MattermostClient\Exception\InvalidArgumentException;
9
use Pnz\MattermostClient\Model\Channel\Channel;
10
use Pnz\MattermostClient\Model\Channel\ChannelMember;
11
use Pnz\MattermostClient\Model\Channel\ChannelMembers;
12
use Pnz\MattermostClient\Model\Channel\ChannelStats;
13
use Pnz\MattermostClient\Model\File\FileMetadata;
14
use Pnz\MattermostClient\Model\Post\Posts;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Pnz\MattermostClient\Api\Posts.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
15
use Pnz\MattermostClient\Model\Status;
16
use Psr\Http\Message\ResponseInterface;
17
18
final class Files extends HttpApi
19
{
20
    /**
21
     * Upload a File to a channel.
22
     *
23
     *
24
     * @see: https://api.mattermost.com/v4/#tag/files%2Fpaths%2F~1files%2Fpost
25
     *
26
     * @return FileInfo|ResponseInterface
27
     */
28
    public function sendFile(string $fileContents, string $channelId, string $clientId = null)
0 ignored issues
show
Unused Code introduced by
The parameter $clientId 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...
29
    {
30
        if (empty($fileContents)) {
31
            throw new InvalidArgumentException('File contents can not be empty');
32
        }
33
34
        if (empty($channelId)) {
35
            throw new InvalidArgumentException('ChannelID can not be empty');
36
        }
37
38
39
        $headers = [];
40
        $multipartStreamBuilder = new MultipartStreamBuilder();
41
42
        // Add channelID
43
        $multipartStreamBuilder->addResource('channel_id', $channelId);
44
        // Add file contents
45
        $multipartStreamBuilder->addResource('files', base64_encode(substr($fileContents, 0, 100)));
46
        // Add client id
47
        $multipartStreamBuilder->addResource('client_ids', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
48
49
        $multipartStream = $multipartStreamBuilder->build();
50
        $headers['Content-Type'] = 'multipart/form-data; boundary='.$multipartStreamBuilder->getBoundary();
51
        $multipartStreamBuilder->reset();
52
53
        //var_dump($fileContents, $multipartStream->getContents(), $headers);
0 ignored issues
show
Unused Code Comprehensibility introduced by
74% 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...
54
55
        $response = $this->httpPostRaw(sprintf('/files', $channelId), $multipartStream, $headers);
56
57
        var_dump($response->getBody()->getContents());
0 ignored issues
show
Security Debugging Code introduced by
var_dump($response->getBody()->getContents()); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
58
59
        // return $this->handleResponse($response, Posts::class);
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
60
    }
61
62
63
    /**
64
     * Get a file metadata.
65
     *
66
     * @param string $fileId
67
     *
68
     * @see https://api.mattermost.com/v4/#tag/files%2Fpaths%2F~1files~1%7Bfile_id%7D~1info%2Fget
69
     *
70
     * @return FileMetadata|ResponseInterface
71
     */
72 View Code Duplication
    public function getFileMetadata(string $fileId)
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...
73
    {
74
        if (empty($fileId)) {
75
            throw new InvalidArgumentException('FileID can not be empty');
76
        }
77
78
        $response = $this->httpGet(sprintf('/files/%s', $fileId));
79
80
        return $this->handleResponse($response, FileMetadata::class);
81
    }
82
}
83