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
Push — 2.9 ( bdebac...8a6b2d )
by Thorsten
13:40
created

PMF_Instance_Elasticsearch   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 61
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A createIndex() 0 6 1
A dropIndex() 0 6 1
A getParams() 0 14 1
1
<?php
2
3
use Elasticsearch\Client;
4
5
/**
6
 * The phpMyFAQ instances basic Elasticsearch class.
7
 *
8
 * PHP Version 5.5
9
 *
10
 * This Source Code Form is subject to the terms of the Mozilla Public License,
11
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
12
 * obtain one at http://mozilla.org/MPL/2.0/
13
 *
14
 * @category  phpMyFAQ
15
 * @author    Thorsten Rinne <[email protected]>
16
 * @copyright 2015 phpMyFAQ Team
17
 * @license   http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
18
 * @link      http://www.phpmyfaq.de
19
 * @since     2015-12-25
20
 */
21
if (!defined('IS_VALID_PHPMYFAQ')) {
22
    exit();
23
}
24
25
/**
26
 * PMF_Instance_Elasticsearch.
27
 *
28
 * @category  phpMyFAQ
29
 * @author    Thorsten Rinne <[email protected]>
30
 * @copyright 2015 phpMyFAQ Team
31
 * @license   http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
32
 * @link      http://www.phpmyfaq.de
33
 * @since     2015-12-25
34
 */
35
class PMF_Instance_Elasticsearch
36
{
37
    /** @var PMF_Configuration */
38
    protected $config;
39
40
    /** @var Client */
41
    protected $client;
42
43
    /**
44
     * Constructor.
45
     *
46
     * @param PMF_Configuration $config
47
     */
48
    public function __construct(PMF_Configuration $config, Client $client)
49
    {
50
        $this->config = $config;
51
        $this->client = $client;
52
    }
53
54
    /**
55
     * Creates the Elasticsearch index.
56
     *
57
     */
58
    public function createIndex()
59
    {
60
        $response = $this->client->indices()->create($this->getParams());
0 ignored issues
show
Unused Code introduced by
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
61
62
63
    }
64
65
    /**
66
     * Deletes the Elasticsearch index.
67
     *
68
     */
69
    public function dropIndex()
70
    {
71
        $config = $this->config->getElasticsearchConfig();
72
73
        $response = $this->client->indices()->delete(['index' => $config['index']]);
0 ignored issues
show
Unused Code introduced by
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
74
    }
75
76
    /**
77
     * Returns the basic phpMyFAQ index structure as raw array.
78
     *
79
     * @return array
80
     */
81
    private function getParams()
82
    {
83
        $config = $this->config->getElasticsearchConfig();
84
85
        return [
86
            'index' => $config['index'],
87
            'body' => [
88
                'settings' => [
89
                    'number_of_shards' => 2,
90
                    'number_of_replicas' => 1
91
                ]
92
            ]
93
        ];
94
    }
95
}
96