Skip to content

Commit aaeca41

Browse files
committed
Fix PHP Codesniffer whitespace violations.
1 parent 019da73 commit aaeca41

41 files changed

Lines changed: 3399 additions & 3142 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

init.php

Lines changed: 75 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -2,85 +2,89 @@
22

33
// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols
44

5-
require_once(__DIR__ . "/config.php");
6-
require_once(__DIR__ . "/vendor/autoload.php");
7-
8-
use Pdsinterop\PhpSolid\Server;
9-
10-
function initKeys() {
11-
$keys = Server::generateKeySet();
12-
file_put_contents(KEYDIR . "public.key", $keys['publicKey']);
13-
file_put_contents(KEYDIR . "private.key", $keys['privateKey']);
14-
file_put_contents(KEYDIR . "encryption.key", $keys['encryptionKey']);
15-
}
5+
require_once(__DIR__ . "/config.php");
6+
require_once(__DIR__ . "/vendor/autoload.php");
7+
8+
use Pdsinterop\PhpSolid\Server;
9+
10+
function initKeys()
11+
{
12+
$keys = Server::generateKeySet();
13+
file_put_contents(KEYDIR . "public.key", $keys['publicKey']);
14+
file_put_contents(KEYDIR . "private.key", $keys['privateKey']);
15+
file_put_contents(KEYDIR . "encryption.key", $keys['encryptionKey']);
16+
}
1617

17-
function initDatabase() {
18-
$statements = [
19-
'CREATE TABLE IF NOT EXISTS clients (
20-
clientId VARCHAR(255) NOT NULL PRIMARY KEY,
21-
origin TEXT NOT NULL,
22-
clientData TEXT NOT NULL
23-
)',
24-
'CREATE TABLE IF NOT EXISTS allowedClients (
25-
userId VARCHAR(255) NOT NULL PRIMARY KEY,
26-
clientId VARCHAR(255) NOT NULL
27-
)',
28-
'CREATE TABLE IF NOT EXISTS userStorage (
29-
userId VARCHAR(255) NOT NULL PRIMARY KEY,
30-
storageUrl VARCHAR(255) NOT NULL
31-
)',
32-
'CREATE TABLE IF NOT EXISTS verify (
33-
code VARCHAR(255) NOT NULL PRIMARY KEY,
34-
data TEXT NOT NULL
35-
)',
36-
'CREATE TABLE IF NOT EXISTS jti (
37-
jti VARCHAR(255) NOT NULL PRIMARY KEY,
38-
expires TEXT NOT NULL
39-
)',
40-
'CREATE TABLE IF NOT EXISTS users (
41-
user_id VARCHAR(255) NOT NULL PRIMARY KEY,
42-
email TEXT NOT NULL,
43-
password TEXT NOT NULL,
44-
data TEXT
45-
)',
46-
'CREATE TABLE IF NOT EXISTS ipAttempts (
47-
ip VARCHAR(255) NOT NULL,
48-
type VARCHAR(255) NOT NULL,
49-
expires TEXT NOT NULL
50-
)',
51-
];
52-
53-
try {
54-
$pdo = new \PDO("sqlite:" . DBPATH);
18+
function initDatabase()
19+
{
20+
$statements = [
21+
'CREATE TABLE IF NOT EXISTS clients (
22+
clientId VARCHAR(255) NOT NULL PRIMARY KEY,
23+
origin TEXT NOT NULL,
24+
clientData TEXT NOT NULL
25+
)',
26+
'CREATE TABLE IF NOT EXISTS allowedClients (
27+
userId VARCHAR(255) NOT NULL PRIMARY KEY,
28+
clientId VARCHAR(255) NOT NULL
29+
)',
30+
'CREATE TABLE IF NOT EXISTS userStorage (
31+
userId VARCHAR(255) NOT NULL PRIMARY KEY,
32+
storageUrl VARCHAR(255) NOT NULL
33+
)',
34+
'CREATE TABLE IF NOT EXISTS verify (
35+
code VARCHAR(255) NOT NULL PRIMARY KEY,
36+
data TEXT NOT NULL
37+
)',
38+
'CREATE TABLE IF NOT EXISTS jti (
39+
jti VARCHAR(255) NOT NULL PRIMARY KEY,
40+
expires TEXT NOT NULL
41+
)',
42+
'CREATE TABLE IF NOT EXISTS users (
43+
user_id VARCHAR(255) NOT NULL PRIMARY KEY,
44+
email TEXT NOT NULL,
45+
password TEXT NOT NULL,
46+
data TEXT
47+
)',
48+
'CREATE TABLE IF NOT EXISTS ipAttempts (
49+
ip VARCHAR(255) NOT NULL,
50+
type VARCHAR(255) NOT NULL,
51+
expires TEXT NOT NULL
52+
)',
53+
];
5554

56-
// create tables
57-
foreach($statements as $statement){
55+
try {
56+
$pdo = new \PDO("sqlite:" . DBPATH);
57+
58+
// create tables
59+
foreach ($statements as $statement) {
5860
$pdo->exec($statement);
59-
}
60-
} catch(\PDOException $e) {
61-
echo $e->getMessage();
6261
}
62+
} catch (\PDOException $e) {
63+
echo $e->getMessage();
6364
}
65+
}
6466

65-
function initStorageDatabase() {
66-
$statements = [
67-
'CREATE TABLE IF NOT EXISTS storage (
68-
storage_id VARCHAR(255) NOT NULL PRIMARY KEY,
69-
owner VARCHAR(255) NOT NULL
70-
)'
71-
];
67+
function initStorageDatabase()
68+
{
69+
$statements = [
70+
'CREATE TABLE IF NOT EXISTS storage (
71+
storage_id VARCHAR(255) NOT NULL PRIMARY KEY,
72+
owner VARCHAR(255) NOT NULL
73+
)'
74+
];
7275

73-
try {
74-
$pdo = new \PDO("sqlite:" . DBPATH);
76+
try {
77+
$pdo = new \PDO("sqlite:" . DBPATH);
7578

76-
// create tables
77-
foreach($statements as $statement){
79+
// create tables
80+
foreach ($statements as $statement) {
7881
$pdo->exec($statement);
79-
}
80-
} catch(\PDOException $e) {
81-
echo $e->getMessage();
8282
}
83+
} catch (\PDOException $e) {
84+
echo $e->getMessage();
8385
}
84-
initKeys();
85-
initDatabase();
86-
initStorageDatabase();
86+
}
87+
88+
initKeys();
89+
initDatabase();
90+
initStorageDatabase();

lib/ClientRegistration.php

Lines changed: 68 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,78 @@
11
<?php
2-
namespace Pdsinterop\PhpSolid;
32

4-
use Pdsinterop\PhpSolid\Db;
3+
namespace Pdsinterop\PhpSolid;
54

6-
class ClientRegistration {
7-
public static function getRegistration($clientId) {
8-
Db::connect();
9-
$query = Db::$pdo->prepare(
10-
'SELECT clientData FROM clients WHERE clientId=:clientId'
11-
);
12-
$query->execute([
13-
':clientId' => $clientId
14-
]);
15-
$result = $query->fetchAll();
16-
if (sizeof($result) === 1) {
17-
return json_decode($result[0]['clientData'], true);
18-
}
19-
if (preg_match("/^http(s)?:/", $clientId)) {
20-
$clientData = self::getRemoteRegistration($clientId);
21-
if (!isset($clientData['origin']) && isset($clientData['client_uri'])) {
22-
$clientData['origin'] = rtrim($clientData['client_uri'], '/');
23-
}
24-
self::saveClientRegistration($clientData);
25-
return $clientData;
5+
use Pdsinterop\PhpSolid\Db;
6+
7+
class ClientRegistration
8+
{
9+
public static function getRegistration($clientId)
10+
{
11+
Db::connect();
12+
$query = Db::$pdo->prepare(
13+
'SELECT clientData FROM clients WHERE clientId=:clientId'
14+
);
15+
$query->execute([
16+
':clientId' => $clientId
17+
]);
18+
$result = $query->fetchAll();
19+
if (sizeof($result) === 1) {
20+
return json_decode($result[0]['clientData'], true);
21+
}
22+
if (preg_match("/^http(s)?:/", $clientId)) {
23+
$clientData = self::getRemoteRegistration($clientId);
24+
if (!isset($clientData['origin']) && isset($clientData['client_uri'])) {
25+
$clientData['origin'] = rtrim($clientData['client_uri'], '/');
2626
}
27-
return false;
27+
self::saveClientRegistration($clientData);
28+
return $clientData;
2829
}
30+
return false;
31+
}
2932

30-
public static function getRemoteRegistration($url) {
31-
$clientDocument = file_get_contents($url);
32-
$clientRegistration = json_decode($clientDocument, true);
33-
if (!isset($clientRegistration['client_id'])) {
34-
throw new \Exception("No client ID found in client document");
35-
}
36-
if (!isset($clientRegistration['redirect_uris'])) {
37-
throw new \Exception("No redirect URIs found in client document");
38-
}
39-
return $clientRegistration;
33+
public static function getRemoteRegistration($url)
34+
{
35+
$clientDocument = file_get_contents($url);
36+
$clientRegistration = json_decode($clientDocument, true);
37+
if (!isset($clientRegistration['client_id'])) {
38+
throw new \Exception("No client ID found in client document");
4039
}
40+
if (!isset($clientRegistration['redirect_uris'])) {
41+
throw new \Exception("No redirect URIs found in client document");
42+
}
43+
return $clientRegistration;
44+
}
4145

42-
public static function saveClientRegistration($clientData) {
43-
Db::connect();
44-
if (!isset($clientData['client_name'])) {
45-
$clientData['client_name'] = $clientData['origin'];
46-
}
47-
$query = Db::$pdo->prepare(
48-
'INSERT INTO clients VALUES(:clientId, :origin, :clientData)'
49-
);
50-
$query->execute([
51-
':clientId' => $clientData['client_id'],
52-
':origin' => $clientData['origin'],
53-
':clientData' => json_encode($clientData)
54-
]);
46+
public static function saveClientRegistration($clientData)
47+
{
48+
Db::connect();
49+
if (!isset($clientData['client_name'])) {
50+
$clientData['client_name'] = $clientData['origin'];
5551
}
56-
57-
public static function getClientByOrigin($origin) {
58-
Db::connect();
59-
$query = Db::$pdo->prepare(
60-
'SELECT clientData FROM clients WHERE origin=:origin'
61-
);
62-
$query->execute([
63-
':origin' => $origin
64-
]);
65-
$result = $query->fetchAll();
66-
67-
if (sizeof($result)=== 1) {
68-
return json_decode($result[0]['clientData'], true);
69-
}
70-
return false;
52+
$query = Db::$pdo->prepare(
53+
'INSERT INTO clients VALUES(:clientId, :origin, :clientData)'
54+
);
55+
$query->execute([
56+
':clientId' => $clientData['client_id'],
57+
':origin' => $clientData['origin'],
58+
':clientData' => json_encode($clientData)
59+
]);
60+
}
61+
62+
public static function getClientByOrigin($origin)
63+
{
64+
Db::connect();
65+
$query = Db::$pdo->prepare(
66+
'SELECT clientData FROM clients WHERE origin=:origin'
67+
);
68+
$query->execute([
69+
':origin' => $origin
70+
]);
71+
$result = $query->fetchAll();
72+
73+
if (sizeof($result) === 1) {
74+
return json_decode($result[0]['clientData'], true);
7175
}
72-
}
76+
return false;
77+
}
78+
}

lib/Db.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<?php
2-
namespace Pdsinterop\PhpSolid;
3-
4-
class Db {
5-
public static $pdo;
6-
public static function connect() {
7-
if (!isset(self::$pdo)) {
8-
self::$pdo = new \PDO("sqlite:" . DBPATH);
9-
}
2+
3+
namespace Pdsinterop\PhpSolid;
4+
5+
class Db
6+
{
7+
public static $pdo;
8+
public static function connect()
9+
{
10+
if (!isset(self::$pdo)) {
11+
self::$pdo = new \PDO("sqlite:" . DBPATH);
1012
}
1113
}
14+
}

0 commit comments

Comments
 (0)