Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .config/phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0"?>
<ruleset
xsi:noNamespaceSchemaLocation="https://schema.phpcodesniffer.com/phpcs.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="PDS Interop PHP Solid Server"
>
<description>PHP coding standards for the PDS Interop PHP Solid Server project</description>

<!-- Show sniff codes in all reports, and progress when running -->
<arg value="sp"/>

<!-- Strip the file paths down to the relevant bit. -->
<arg name="basepath" value="../"/>
<arg name="extensions" value="php"/>
<arg name="colors"/>

<file>.</file>
<exclude-pattern>*(.config|vendor)/*</exclude-pattern>

<rule ref="PHPCompatibility"/>
<config name="testVersion" value="8.0-"/>

<!-- Set indent for `break` to 0 so it aligns with `case` and `default` -->
<rule ref="PSR2">
<exclude name="PSR2.ControlStructures.SwitchDeclaration"/>
<exclude name="PSR2.ControlStructures.ElseIfDeclaration.NotAllowed"/>
<exclude name="PSR2.ControlStructures.ControlStructureSpacing.SpacingAfterOpenBrace"/>
</rule>

<!-- Enforce the use of tabs for indentation -->
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>

<!-- Include the whole PSR-12 standard -->
<rule ref="PSR12">
<!-- Enforce the use of tabs for indentation -->
<exclude name="Generic.WhiteSpace.DisallowTabIndent.NonIndentTabsUsed"/>
<exclude name="Generic.WhiteSpace.DisallowTabIndent.TabsUsed"/>

<!-- Do not align multiple statements, to reduce noise in diffs -->
<exclude name="Generic.Formatting.MultipleStatementAlignment.NotSame"/>
</rule>

<!-- Have 12 chars padding maximum and always show as errors -->
<rule ref="Generic.Formatting.MultipleStatementAlignment">
<properties>
<property name="maxPadding" value="12"/>
<property name="error" value="true"/>
</properties>
</rule>
</ruleset>
24 changes: 24 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
root = true

[*.php]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = tab
insert_final_newline = true
max_line_length = 120
spelling_language = en-US
tab_width = 4
trim_trailing_whitespace = true

# Unset settings for vendor directories
[{node_modules,vendor}/**]
charset = unset
end_of_line = unset
indent_size = unset
indent_style = unset
insert_final_newline = unset
max_line_length = unset
spelling_language = unset
tab_width = unset
trim_trailing_whitespace = unset
16 changes: 16 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# List of revisions that are hidden from git blame annotations.
#
# This concerns massive code re-formatting, renaming, large changes
# that were later reverted, etc.
#
# Configure your git so that it always ignores the revisions listed
# in this file:
#
# git config blame.ignoreRevsFile .git-blame-ignore-revs
#
# When adding a new revision to the list, please put its commit message
# in a comment above it.


# Mass fix of PHP Codesniffer whitespace violations
aaeca415e39669aae893f2fde47cf2ae04a6a287
23 changes: 22 additions & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ jobs:
--exclude vendor
--no-progress
.
# # 01.quality.php.validate.dependencies-file.yml

# 01.quality.php.validate.dependencies-file.yml
validate-dependencies-file:
name: Validate dependencies file
runs-on: ubuntu-24.04
Expand All @@ -63,6 +64,7 @@ jobs:
--no-plugins
--no-scripts
--strict

# 02.test.php.test-unit.yml
php-unittest:
name: PHP Unit Tests
Expand All @@ -89,6 +91,7 @@ jobs:
env:
COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.GITHUB_TOKEN }}"}}'
- run: vendor/bin/phpunit --configuration tests/phpunit/phpunit.xml

# 03.quality.php.scan.dependencies-vulnerabilities.yml
scan-dependencies-vulnerabilities:
name: Scan Dependencies Vulnerabilities
Expand All @@ -107,6 +110,24 @@ jobs:
--no-dev
--no-plugins
--no-scripts


# 03.quality.php.lint-quality.yml
php-lint-quality:
needs:
- lint-php-syntax
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: docker://pipelinecomponents/php-codesniffer
with:
args: >-
phpcs
--standard=.config/phpcs.xml.dist
--report-full
--report-summary
.

# 03.quality.php.lint-version-compatibility.yml
php-check-version-compatibility:
name: PHP Version Compatibility
Expand Down
149 changes: 78 additions & 71 deletions init.php
Original file line number Diff line number Diff line change
@@ -1,83 +1,90 @@
<?php
require_once(__DIR__ . "/config.php");
require_once(__DIR__ . "/vendor/autoload.php");

use Pdsinterop\PhpSolid\Server;

function initKeys() {
$keys = Server::generateKeySet();
file_put_contents(KEYDIR . "public.key", $keys['publicKey']);
file_put_contents(KEYDIR . "private.key", $keys['privateKey']);
file_put_contents(KEYDIR . "encryption.key", $keys['encryptionKey']);
}

function initDatabase() {
$statements = [
'CREATE TABLE IF NOT EXISTS clients (
clientId VARCHAR(255) NOT NULL PRIMARY KEY,
origin TEXT NOT NULL,
clientData TEXT NOT NULL
)',
'CREATE TABLE IF NOT EXISTS allowedClients (
userId VARCHAR(255) NOT NULL PRIMARY KEY,
clientId VARCHAR(255) NOT NULL
)',
'CREATE TABLE IF NOT EXISTS userStorage (
userId VARCHAR(255) NOT NULL PRIMARY KEY,
storageUrl VARCHAR(255) NOT NULL
)',
'CREATE TABLE IF NOT EXISTS verify (
code VARCHAR(255) NOT NULL PRIMARY KEY,
data TEXT NOT NULL
)',
'CREATE TABLE IF NOT EXISTS jti (
jti VARCHAR(255) NOT NULL PRIMARY KEY,
expires TEXT NOT NULL
)',
'CREATE TABLE IF NOT EXISTS users (
user_id VARCHAR(255) NOT NULL PRIMARY KEY,
email TEXT NOT NULL,
password TEXT NOT NULL,
data TEXT
)',
'CREATE TABLE IF NOT EXISTS ipAttempts (
ip VARCHAR(255) NOT NULL,
type VARCHAR(255) NOT NULL,
expires TEXT NOT NULL
)',
];

try {
$pdo = new \PDO("sqlite:" . DBPATH);
// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols

require_once(__DIR__ . "/config.php");
require_once(__DIR__ . "/vendor/autoload.php");

use Pdsinterop\PhpSolid\Server;

function initKeys()
{
$keys = Server::generateKeySet();
file_put_contents(KEYDIR . "public.key", $keys['publicKey']);
file_put_contents(KEYDIR . "private.key", $keys['privateKey']);
file_put_contents(KEYDIR . "encryption.key", $keys['encryptionKey']);
}

// create tables
foreach($statements as $statement){
function initDatabase()
{
$statements = [
'CREATE TABLE IF NOT EXISTS clients (
clientId VARCHAR(255) NOT NULL PRIMARY KEY,
origin TEXT NOT NULL,
clientData TEXT NOT NULL
)',
'CREATE TABLE IF NOT EXISTS allowedClients (
userId VARCHAR(255) NOT NULL PRIMARY KEY,
clientId VARCHAR(255) NOT NULL
)',
'CREATE TABLE IF NOT EXISTS userStorage (
userId VARCHAR(255) NOT NULL PRIMARY KEY,
storageUrl VARCHAR(255) NOT NULL
)',
'CREATE TABLE IF NOT EXISTS verify (
code VARCHAR(255) NOT NULL PRIMARY KEY,
data TEXT NOT NULL
)',
'CREATE TABLE IF NOT EXISTS jti (
jti VARCHAR(255) NOT NULL PRIMARY KEY,
expires TEXT NOT NULL
)',
'CREATE TABLE IF NOT EXISTS users (
user_id VARCHAR(255) NOT NULL PRIMARY KEY,
email TEXT NOT NULL,
password TEXT NOT NULL,
data TEXT
)',
'CREATE TABLE IF NOT EXISTS ipAttempts (
ip VARCHAR(255) NOT NULL,
type VARCHAR(255) NOT NULL,
expires TEXT NOT NULL
)',
];

try {
$pdo = new \PDO("sqlite:" . DBPATH);

// create tables
foreach ($statements as $statement) {
$pdo->exec($statement);
}
} catch(\PDOException $e) {
echo $e->getMessage();
}
} catch (\PDOException $e) {
echo $e->getMessage();
}
}

function initStorageDatabase() {
$statements = [
'CREATE TABLE IF NOT EXISTS storage (
storage_id VARCHAR(255) NOT NULL PRIMARY KEY,
owner VARCHAR(255) NOT NULL
)'
];
function initStorageDatabase()
{
$statements = [
'CREATE TABLE IF NOT EXISTS storage (
storage_id VARCHAR(255) NOT NULL PRIMARY KEY,
owner VARCHAR(255) NOT NULL
)'
];

try {
$pdo = new \PDO("sqlite:" . DBPATH);
try {
$pdo = new \PDO("sqlite:" . DBPATH);

// create tables
foreach($statements as $statement){
// create tables
foreach ($statements as $statement) {
$pdo->exec($statement);
}
} catch(\PDOException $e) {
echo $e->getMessage();
}
} catch (\PDOException $e) {
echo $e->getMessage();
}
initKeys();
initDatabase();
initStorageDatabase();
}

initKeys();
initDatabase();
initStorageDatabase();
Loading
Loading