Completed
Push — master ( 04c9ff...5dea00 )
by Alex
03:36
created

HttpCalls::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: alumne
5
 * Date: 31/05/16
6
 * Time: 14:04
7
 */
8
9
namespace App\Console\AuxiliaryClasses;
10
11
use App\InteractionMethodsMOD\GetMethods;
12
13
/**
14
 * Class HttpCalls
15
 * @package App\Console\AuxiliaryClasses
16
 */
17
class HttpCalls
18
{
19
    /**
20
     * @var GetMethods
21
     */
22
    protected $get_methods;
23
24
    /**
25
     * HttpCalls constructor.
26
     * @param GetMethods $get_methods
27
     */
28
    public function __construct(GetMethods $get_methods)
29
    {
30
        $this->get_methods=$get_methods;
31
    }
32
33
    /**
34
     * @param $symbol
35
     * @return mixed|\Psr\Http\Message\ResponseInterface
36
     */
37
    public function getTableFollow($symbol)
38
    {
39
        $data=$this->get_methods->stockQuote($symbol);
40
41
        sleep(4);
42
43
        return $data;
44
    }
45
46
    public function getExchangeHistory($symbol)
47
    {
48
        $data=$this->get_methods->interactiveChart($symbol);
49
50
        sleep(4);
51
52
        return $data;
53
    }
54
55
    public function getCompanies($symbol)
56
    {
57
        $data=$this->get_methods->companyLookup($symbol);
58
59
        $data=$this->discardRepeated($data,$symbol);
60
61
        sleep(4);
62
63
        return $data;
64
    }
65
66
    /**
67
     * @param $data
68
     * @param $symbol
69
     * @return $node
0 ignored issues
show
Documentation introduced by
The doc-type $node could not be parsed: Unknown type name "$node" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
70
     * @return null
71
     */
72
    private function discardRepeated($data, $symbol)
73
    {
74
        for($i=0;$i<count($data);$i++){
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
75
76
            $symbol_to_compare=(string) $data[$i]->Symbol;
77
78
            if($symbol_to_compare==$symbol){
79
                return $node=$data[$i];
0 ignored issues
show
Unused Code introduced by
$node 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...
80
            }
81
82
        }
83
        return null;
84
    }
85
86
87
}