Completed
Push — master ( 0a2d54...99fa2d )
by
unknown
02:12
created

Game::checkIssetImage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 3
crap 2
1
<?php
2
3
namespace Syntax\SteamApi\Containers;
4
5
class Game extends BaseContainer
6
{
7
    public $appId;
8
9
    public $name;
10
11
    public $playtimeTwoWeeks;
12
13
    public $playtimeTwoWeeksReadable;
14
15
    public $playtimeForever;
16
17
    public $playtimeForeverReadable;
18
19
    public $icon;
20
21
    public $logo;
22
23
    public $header;
24
25
    public $hasCommunityVisibleStats;
26
27 1
    public function __construct($app)
28
    {
29 1
        $this->appId                    = $app->appid;
30 1
        $this->name                     = $this->checkIssetField($app, 'name');
31 1
        $this->playtimeTwoWeeks         = $this->checkIssetField($app, 'playtime_2weeks', 0);
32 1
        $this->playtimeTwoWeeksReadable = $this->convertFromMinutes($this->playtimeTwoWeeks);
33 1
        $this->playtimeForever          = $this->checkIssetField($app, 'playtime_forever', 0);
34 1
        $this->playtimeForeverReadable  = $this->convertFromMinutes($this->playtimeForever);
35 1
        $this->icon                     = $this->checkIssetImage($app, 'img_icon_url');
36 1
        $this->logo                     = $this->checkIssetImage($app, 'img_logo_url');
37 1
        $this->header                   = 'http://cdn.akamai.steamstatic.com/steam/apps/' . $this->appId . '/header.jpg';
38 1
        $this->hasCommunityVisibleStats = $this->checkIssetField($app, 'has_community_visible_stats', 0);
39 1
    }
40
41
    /**
42
     * @param        $app
43
     * @param string $field
44
     * @param string $value
45
     *
46
     * @return null|string
47
     */
48 1
    protected function checkIssetImage($app, $field, $value = null)
49
    {
50 1
        return isset($app->$field) ? $this->getImageForGame($app->appid, $app->$field) : $value;
51
    }
52
53 1
    protected function getImageForGame($appId, $hash)
54
    {
55 1
        if ($hash != null) {
56 1
            return 'http://media.steampowered.com/steamcommunity/public/images/apps/' . $appId . '/' . $hash . '.jpg';
57
        }
58
59 1
        return null;
60
    }
61
}
62