Skip to content

Commit 91c8be7

Browse files
author
Peter Lohse
committed
Umstellung auf PSR-12
1 parent 1dfec18 commit 91c8be7

8 files changed

Lines changed: 185 additions & 109 deletions

File tree

.github/workflows/codestyle.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: PHPCS check
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
phpcs:
8+
name: PHPCS
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- name: PHPCS check
13+
uses: chekalsky/phpcs-action@v1

.php_cs.dist

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
$finder = PhpCsFixer\Finder::create()
3+
->in(__DIR__.'/files/')
4+
->notPath('lib/system/api');
5+
6+
return (new PhpCsFixer\Config())
7+
->setRiskyAllowed(true)
8+
->setRules([
9+
'@PSR1' => true,
10+
'@PSR2' => true,
11+
])
12+
->setFinder($finder);

.phpcs.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
3+
<arg name="basepath" value="."/>
4+
<arg name="cache" value=".phpcs-cache"/>
5+
<arg name="colors"/>
6+
<arg name="extensions" value="php"/>
7+
<arg name="parallel" value="10"/>
8+
9+
<!-- Show progress -->
10+
<arg value="p"/>
11+
12+
<!-- Paths to check -->
13+
<file>files</file>
14+
<exclude-pattern>lib/system/api/*</exclude-pattern>
15+
16+
<!-- Include all rules from the Zend Coding Standard -->
17+
<rule ref="PSR12"/>
18+
19+
<!-- TODO: auskommentieren -->
20+
<rule ref="Generic.Files.LineLength">
21+
<properties>
22+
<property name="lineLimit" value="N"/>
23+
<property name="absoluteLineLimit" value="M"/>
24+
</properties>
25+
</rule>
26+
</ruleset>
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<?php
2+
23
namespace wcf\system\exception;
34

45
/**
56
* Steam exception
67
*
78
* @author Peter Lohse <hanashi@hanashi.eu>
89
* @copyright Hanashi Development
9-
* @license Freie Lizenz (https://hanashi.eu/freie-lizenz/)
10-
* @package WoltLabSuite\Core\System\Exception
10+
* @license Freie Lizenz (https://hanashi.eu/freie-lizenz/)
11+
* @package WoltLabSuite\Core\System\Exception
1112
*/
12-
class SteamException extends SystemException {}
13+
class SteamException extends SystemException
14+
{
15+
}
Lines changed: 105 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
2+
23
namespace wcf\system\steam;
4+
35
use wcf\system\exception\SteamException;
46
use wcf\system\exception\SystemException;
57
use wcf\util\exception\HTTPException;
@@ -11,117 +13,129 @@
1113
* Steam Web Api class
1214
* api key can got from here: https://steamcommunity.com/dev/apikey
1315
* method documentation is from original documentations
14-
*
16+
*
1517
* @see https://openid.net/specs/openid-authentication-2_0.html
1618
* @see https://api.steampowered.com/ISteamWebAPIUtil/GetSupportedAPIList/v1/?key=<HA_STEAM_API_KEY>
17-
*
19+
*
1820
* @author Peter Lohse <hanashi@hanashi.eu>
1921
* @copyright Hanashi Development
20-
* @license Freie Lizenz (https://hanashi.dev/freie-lizenz/)
21-
* @package WoltLabSuite\Core\System\Steam
22+
* @license Freie Lizenz (https://hanashi.dev/freie-lizenz/)
23+
* @package WoltLabSuite\Core\System\Steam
2224
*/
23-
class SteamAPI {
24-
/**
25-
* execute a Steam API call
26-
*
27-
* @var string $interface Steam API interface
28-
* @var string $method API method that should be executed
29-
* @var int $version version of API method
30-
* @var array $data API method parameters
31-
* @var string $httpmethod HTTP method e.g. GET or POST
32-
* @var bool $useJSON use json e.g. for GetOwnedGames
33-
* @return array/string returns an array or a string of Steam API answer
34-
*/
35-
public static function execute(string $interface, string $method, int $version, array $data = [], string $httpmethod = 'GET', bool $useJSON = false) {
36-
if (!HA_STEAM_API_KEY) throw new SteamException('Steam API key not configured.');
25+
class SteamAPI
26+
{
27+
/**
28+
* execute a Steam API call
29+
*
30+
* @var string $interface Steam API interface
31+
* @var string $method API method that should be executed
32+
* @var int $version version of API method
33+
* @var array $data API method parameters
34+
* @var string $httpmethod HTTP method e.g. GET or POST
35+
* @var bool $useJSON use json e.g. for GetOwnedGames
36+
* @return array/string returns an array or a string of Steam API answer
37+
*/
38+
public static function execute(string $interface, string $method, int $version, array $data = [], string $httpmethod = 'GET', bool $useJSON = false)
39+
{
40+
if (!HA_STEAM_API_KEY) {
41+
throw new SteamException('Steam API key not configured.');
42+
}
3743

38-
$parameters = [
39-
'format' => 'json',
40-
'key' => HA_STEAM_API_KEY
41-
];
42-
if ($useJSON && count($data)) {
43-
$parameters['input_json'] = JSON::encode($data);
44-
} else {
45-
$parameters = array_merge($parameters, $data);
46-
}
44+
$parameters = [
45+
'format' => 'json',
46+
'key' => HA_STEAM_API_KEY
47+
];
48+
if ($useJSON && count($data)) {
49+
$parameters['input_json'] = JSON::encode($data);
50+
} else {
51+
$parameters = array_merge($parameters, $data);
52+
}
4753

48-
$apiURL = 'http://api.steampowered.com/' . $interface . '/' . $method . '/v' . $version . '/';
54+
$apiURL = 'http://api.steampowered.com/' . $interface . '/' . $method . '/v' . $version . '/';
4955

50-
$postParameters = [];
51-
if ($httpmethod == 'GET') {
52-
$apiURL .= '?' . http_build_query($parameters, null, '&');
53-
} else {
54-
$postParameters = $parameters;
55-
}
56+
$postParameters = [];
57+
if ($httpmethod == 'GET') {
58+
$apiURL .= '?' . http_build_query($parameters, null, '&');
59+
} else {
60+
$postParameters = $parameters;
61+
}
5662

57-
$request = new HTTPRequest($apiURL, ['method' => $httpmethod], $postParameters);
58-
try {
59-
$request->execute();
60-
$reply = $request->getReply();
61-
try {
62-
return JSON::decode($reply['body'], true);
63-
} catch (SystemException $e) {
64-
return $reply['body'];
65-
}
66-
} catch (HTTPException $e) {
67-
throw new SteamException('Wrong Steam API call or Steam API is not reachable. (Message: ' . $e->getMessage() . ')');
68-
} catch (SystemException $e) {
69-
$reply = $request->getReply();
70-
try {
71-
return JSON::decode($reply['body'], true);
72-
} catch (SystemException $e) {
73-
return $reply['body'];
74-
}
75-
}
76-
}
63+
$request = new HTTPRequest($apiURL, ['method' => $httpmethod], $postParameters);
64+
try {
65+
$request->execute();
66+
$reply = $request->getReply();
67+
try {
68+
return JSON::decode($reply['body'], true);
69+
} catch (SystemException $e) {
70+
return $reply['body'];
71+
}
72+
} catch (HTTPException $e) {
73+
throw new SteamException('Wrong Steam API call or Steam API is not reachable. (Message: ' . $e->getMessage() . ')');
74+
} catch (SystemException $e) {
75+
$reply = $request->getReply();
76+
try {
77+
return JSON::decode($reply['body'], true);
78+
} catch (SystemException $e) {
79+
return $reply['body'];
80+
}
81+
}
82+
}
7783

78-
/********************* OpenID *********************/
84+
/********************* OpenID *********************/
7985

80-
/**
81-
* get OpenID login url
82-
*
83-
* @var string $redirectUri URL to which the OP SHOULD return the User-Agent with the response indicating the status of the request.
84-
* @var string $realm URL pattern the OP SHOULD ask the end user to trust.
85-
* @return string
86-
*/
87-
public static function getOpenIDUrl(string $redirectUri, string $realm) : string {
88-
$data = [
89-
'openid.ns' => 'http://specs.openid.net/auth/2.0',
90-
'openid.mode' => 'checkid_setup',
91-
'openid.return_to' => $redirectUri,
92-
'openid.realm' => $realm,
93-
'openid.claimed_id' => 'http://specs.openid.net/auth/2.0/identifier_select',
94-
'openid.identity' => 'http://specs.openid.net/auth/2.0/identifier_select'
95-
];
96-
return 'https://steamcommunity.com/openid/login?' . http_build_query($data, null, '&');
97-
}
86+
/**
87+
* get OpenID login url
88+
*
89+
* @var string $redirectUri URL to which the OP SHOULD return the User-Agent with the response indicating the status of the request.
90+
* @var string $realm URL pattern the OP SHOULD ask the end user to trust.
91+
* @return string
92+
*/
93+
public static function getOpenIDUrl(string $redirectUri, string $realm): string
94+
{
95+
$data = [
96+
'openid.ns' => 'http://specs.openid.net/auth/2.0',
97+
'openid.mode' => 'checkid_setup',
98+
'openid.return_to' => $redirectUri,
99+
'openid.realm' => $realm,
100+
'openid.claimed_id' => 'http://specs.openid.net/auth/2.0/identifier_select',
101+
'openid.identity' => 'http://specs.openid.net/auth/2.0/identifier_select'
102+
];
103+
return 'https://steamcommunity.com/openid/login?' . http_build_query($data, null, '&');
104+
}
98105

99-
/**
100-
* validate OpenID data and returns SteamID
101-
*
102-
* @var array $data content of $_GET by redirect uri, where prefix is "openid."
103-
* @return int 64 bit of SteamID
104-
*/
105-
public static function validateOpenID() : int {
106-
$params = [];
106+
/**
107+
* validate OpenID data and returns SteamID
108+
*
109+
* @var array $data content of $_GET by redirect uri, where prefix is "openid."
110+
* @return int 64 bit of SteamID
111+
*/
112+
public static function validateOpenID(): int
113+
{
114+
$params = [];
107115
foreach ($_GET as $key => $val) {
108116
if (StringUtil::startsWith($key, 'openid')) {
109117
$newKey = 'openid.' . substr($key, 7);
110118
$params[$newKey] = $val;
111119
}
112120
}
113-
$params['openid.mode'] = 'check_authentication';
121+
$params['openid.mode'] = 'check_authentication';
114122

115-
$request = new HTTPRequest('https://steamcommunity.com/openid/login', [], $params);
116-
$request->execute();
117-
$reply = $request->getReply();
118-
$content = $reply['body'];
123+
$request = new HTTPRequest('https://steamcommunity.com/openid/login', [], $params);
124+
$request->execute();
125+
$reply = $request->getReply();
126+
$content = $reply['body'];
119127

120-
if (strpos($content, 'is_valid:true') === false) throw new SteamException('Invalid authentication');
128+
if (strpos($content, 'is_valid:true') === false) {
129+
throw new SteamException('Invalid authentication');
130+
}
121131

122-
if (!preg_match('/^https:\/\/steamcommunity.com\/openid\/id\/([0-9]+)$/', $params['openid.claimed_id'], $matches)) throw new SteamException('Invalid Steam ID');
123-
if (empty($matches[1] || !is_numeric($matches[1]))) throw new SteamException('Invalid Steam ID');
132+
if (!preg_match('/^https:\/\/steamcommunity.com\/openid\/id\/([0-9]+)$/', $params['openid.claimed_id'], $matches)) {
133+
throw new SteamException('Invalid Steam ID');
134+
}
135+
if (empty($matches[1] || !is_numeric($matches[1]))) {
136+
throw new SteamException('Invalid Steam ID');
137+
}
124138

125-
return $matches[1];
126-
}
139+
return $matches[1];
140+
}
127141
}

make.bat

Lines changed: 0 additions & 5 deletions
This file was deleted.

make.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
#!/bin/bash
2-
rm -f files.tar
3-
7z a -ttar -mx=9 files.tar ./files/*
4-
rm -f dev.hanashi.wsc.steam-api.tar
5-
7z a -ttar -mx=9 dev.hanashi.wsc.steam-api.tar ./* -x!acptemplates -x!files -x!templates -x!dev.hanashi.wsc.steam-api.tar -x!.git -x!.gitignore -x!make.bat -x!make.sh
2+
PACKAGE_NAME=dev.hanashi.wsc.steam-api
3+
PACKAGE_TYPES=(files)
4+
5+
for i in "${PACKAGE_TYPES[@]}"
6+
do
7+
rm -rf ${i}.tar
8+
7z a -ttar -mx=9 ${i}.tar ./${i}/*
9+
done
10+
11+
rm -rf ${PACKAGE_NAME}.tar ${PACKAGE_NAME}.tar.gz
12+
7z a -ttar -mx=9 ${PACKAGE_NAME}.tar ./* -x!acptemplates -x!files -x!templates -x!${PACKAGE_NAME}.tar -x!${PACKAGE_NAME}.tar.gz -x!.git -x!.gitignore -x!make.sh -x!make.bat -x!.phpcs.xml -x!.github -x!ts -x!node_modules -x!package-lock.json -x!package.json -x!tsconfig.json
13+
14+
for i in "${PACKAGE_TYPES[@]}"
15+
do
16+
rm -rf ${i}.tar
17+
done
18+

package.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
<packagename language="de"><![CDATA[Steam-API]]></packagename>
66
<packagedescription><![CDATA[Api package for Steam.]]></packagedescription>
77
<packagedescription language="de"><![CDATA[API-Paket für Steam.]]></packagedescription>
8-
<version>1.0.1 pl 1</version>
9-
<date>2020-01-26</date>
8+
<version>1.0.2</version>
9+
<date>2021-07-19</date>
1010
</packageinformation>
1111

1212
<authorinformation>
13-
<author><![CDATA[Hanashi]]></author>
13+
<author><![CDATA[Hanashi Development]]></author>
1414
<authorurl><![CDATA[https://hanashi.dev/]]></authorurl>
1515
</authorinformation>
1616

@@ -34,8 +34,8 @@
3434
<instruction type="option" />
3535
</instructions>
3636

37-
<instructions type="update" fromversion="1.0.1">
38-
<!-- config -->
39-
<instruction type="option" />
37+
<instructions type="update" fromversion="1.0.1 pl 1">
38+
<!-- files -->
39+
<instruction type="file" />
4040
</instructions>
4141
</package>

0 commit comments

Comments
 (0)