Skip to content

Commit 1028826

Browse files
authored
Merge pull request #124 from docusign/feature/add-linter-to-CI-CD
Refactoring the code examples after adding linter to CI/CD
2 parents af2ff93 + 3efd6ad commit 1028826

File tree

197 files changed

+1194
-1080
lines changed

Some content is hidden

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

197 files changed

+1194
-1080
lines changed

.github/workflows/php.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ jobs:
2929
- name: Install dependencies
3030
run: composer install --prefer-dist --no-progress
3131

32+
- name: Run linter
33+
run: vendor/bin/phpcs --standard=phpcs.xml --report=checkstyle src/ -n
34+
3235
- name: Run tests
3336
env:
3437
CLIENT_ID: ${{ secrets.CLIENT_ID }}

JWTConsoleApp/JWTConsoleApp.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

3-
use Example\Services\SignatureClientService;
4-
use Example\Services\Examples\eSignature\SigningViaEmailService;
3+
use DocuSign\Services\SignatureClientService;
4+
use DocuSign\Services\Examples\eSignature\SigningViaEmailService;
55

66
use DocuSign\eSign\Client\ApiClient;
77

JWTConsoleApp/composer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
22
"autoload": {
3-
"psr-4": {"Example\\": "../src/",
4-
"DocuSign\\OAuth2\\Client\\Provider\\": "../src/"
5-
}
3+
"psr-4": {"DocuSign\\": "../src/"}
64
},
75

86
"require": {

Quick_ACG/composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"autoload": {
3-
"psr-4": {"Example\\": "../src/",
4-
"DocuSign\\OAuth2\\Client\\Provider\\": "../src/",
3+
"psr-4": {"DocuSign\\": "../src/",
54
"QuickACG\\": "src/"
65
}
76
},

Quick_ACG/src/RouterService.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace QuickACG;
44

5-
use Example\Services\ApiTypes;
6-
use Example\Services\CodeGrantService;
7-
use Example\Services\ManifestService;
8-
use Example\Services\IRouterService;
5+
use DocuSign\Services\ApiTypes;
6+
use DocuSign\Services\CodeGrantService;
7+
use DocuSign\Services\ManifestService;
8+
use DocuSign\Services\IRouterService;
99

1010
class RouterService implements IRouterService
1111
{
@@ -66,26 +66,26 @@ public function router(): void
6666

6767
switch ($page) {
6868
case 'select_api':
69-
$this->ds_login();
69+
$this->dsLogin();
7070
break;
7171
case 'ds_callback':
72-
$this->ds_callback(); // See below in oauth section
72+
$this->dsCallback(); // See below in oauth section
7373
break;
7474
case 'must_authenticate':
75-
$this->ds_login();
75+
$this->dsLogin();
7676
break;
7777
case 'ds_return':
7878
header('Location: ' . '/public', true);
7979
break;
8080
case 'eg001':
8181
$_SESSION['API_TEXT'] = ManifestService::loadManifestData($GLOBALS['DS_CONFIG']['CodeExamplesManifest']);
82-
$controller = '\Example\\' . $this->getController($page);
82+
$controller = '\DocuSign\\' . $this->getController($page);
8383
new $controller($page);
8484
break;
8585
default:
8686
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING & ~E_DEPRECATED);
8787
$_SESSION['API_TEXT'] = ManifestService::loadManifestData($GLOBALS['DS_CONFIG']['CodeExamplesManifest']);
88-
$controller = '\Example\\' . $this->getController($page);
88+
$controller = '\DocuSign\\' . $this->getController($page);
8989
new $controller($page);
9090
break;
9191
}
@@ -95,7 +95,7 @@ public function router(): void
9595
* @param int $buffer_min buffer time needed in minutes
9696
* @return boolean $ok true iff the user has an access token that will be good for another buffer min
9797
*/
98-
function ds_token_ok(int $buffer_min = 10): bool
98+
function dsTokenOk(int $buffer_min = 10): bool
9999
{
100100
$areTokenAndExprirationSet = isset($_SESSION['ds_access_token']) && isset($_SESSION['ds_expiration']);
101101

@@ -116,7 +116,7 @@ public function getController($eg): string
116116
/**
117117
* Unset all items from the session
118118
*/
119-
function ds_logout_internal(): void
119+
function dsLogoutInternal(): void
120120
{
121121
foreach (self::SESSION_VALUES as &$sessionValue) {
122122
if (isset($_SESSION[$sessionValue])) {
@@ -128,16 +128,16 @@ function ds_logout_internal(): void
128128
/**
129129
* DocuSign login handler
130130
*/
131-
function ds_login(): void
131+
function dsLogin(): void
132132
{
133-
$_SESSION['api_type'] = ApiTypes::eSignature;
133+
$_SESSION['api_type'] = ApiTypes::ESIGNATURE;
134134
$this->authService->login();
135135
}
136136

137137
/**
138138
* Called via a redirect from DocuSign authentication service
139139
*/
140-
function ds_callback(): void
140+
function dsCallback(): void
141141
{
142142
# Save the redirect eg if present
143143
$redirectUrl = false;
@@ -149,7 +149,7 @@ function ds_callback(): void
149149
# reset the session
150150
$tempAPIType = $_SESSION['api_type'];
151151
$tempGrant = $_SESSION['auth_service'];
152-
$this->ds_logout_internal();
152+
$this->dsLogoutInternal();
153153

154154
// Workaround for ACG apiTypePicker
155155
$_SESSION['api_type'] = $tempAPIType;
@@ -169,7 +169,7 @@ public function flash(string $msg): void
169169
/**
170170
* Checker for the CSRF token
171171
*/
172-
function check_csrf(): void
172+
function checkCsrf(): void
173173
{
174174
$this->authService->checkToken();
175175
}

composer.json

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
{
22
"autoload": {
3-
"psr-4": {"Example\\": "src/",
4-
"DocuSign\\OAuth2\\Client\\Provider\\": "src/"
5-
}
3+
"psr-4": {"DocuSign\\": "src/"}
64
},
75
"autoload-dev": {
86
"psr-4": {
9-
"Example\\Tests\\": "tests/"
7+
"DocuSign\\Tests\\": "tests/"
108
}
119
},
1210
"scripts": {
13-
"post-install-cmd": [
14-
"@code-sniffer"
15-
],
16-
"post-update-cmd": [
17-
"@code-sniffer"
18-
],
1911
"test": "./vendor/bin/phpunit --verbose tests"
2012
},
2113
"config": {
@@ -36,5 +28,8 @@
3628
"mashape/unirest-php": "3.0.4",
3729
"squizlabs/php_codesniffer": "*",
3830
"phpunit/phpunit": "^9.5"
31+
},
32+
"require-dev": {
33+
"squizlabs/php_codesniffer": "*"
3934
}
4035
}

composer.lock

Lines changed: 22 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpcs.xml

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0"?>
2-
<ruleset name="igmaDev">
2+
<ruleset name="DocuSign">
33
<file>src/Controllers</file>
44
<file>src/Services</file>
55
<file>src/EG001EmbeddedSigning.php</file>
@@ -9,38 +9,22 @@
99
<exclude-pattern>*/public/assets/*</exclude-pattern>
1010
<exclude-pattern>*/public/demo_documents/*</exclude-pattern>
1111
<arg name="extensions" value="php" />
12-
<rule ref="PEAR">
13-
<exclude name="PEAR.Commenting.FunctionCallSignature.CloseBracketLine" />
14-
<exclude name="PEAR.Files.IncludingFile.UseInclude" />
15-
<exclude name="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket" />
16-
<exclude name="PEAR.Functions.FunctionCallSignature.CloseBracketLine" />
17-
<exclude name="PEAR.Functions.FunctionCallSignature.Indent" />
18-
<exclude name="PEAR.NamingConventions.ValidVariableName.PrivateNoUnderscore" />
19-
<exclude name="PEAR.WhiteSpace.ObjectOperatorIndent.Incorrect" />
20-
</rule>
21-
<rule ref="PSR2">
22-
<exclude name="PSR2.Methods.FunctionCallSignature.CloseBracketLine" />
23-
<exclude name="PSR2.Methods.FunctionCallSignature.ContentAfterOpenBracket" />
24-
<exclude name="PSR2.Methods.FunctionCallSignature.Indent" />
25-
</rule>
26-
<rule ref="PSR2.Namespaces.NamespaceDeclaration.BlankLineAfter" />
12+
<!-- Include basic PHP coding standards -->
13+
<rule ref="PSR1"/>
14+
<rule ref="PSR2"/>
15+
16+
<!-- Exclude comment-related rules -->
17+
<exclude name="Squiz.Commenting.ClassComment"/>
18+
<exclude name="Squiz.Commenting.FunctionComment"/>
19+
<exclude name="Squiz.Commenting.VariableComment"/>
20+
<exclude name="Generic.Commenting.DocComment"/>
21+
<exclude name="Generic.Files.LineEndings.InvalidEOLChar"/>
22+
23+
<!-- Define other rules and configurations here -->
2724
<rule ref="Generic.Files.LineLength">
2825
<properties>
2926
<property name="lineLimit" value="90"/>
3027
<property name="absoluteLineLimit" value="130"/>
3128
</properties>
3229
</rule>
33-
<rule ref="Generic.Commenting.DocComment.MissingShort">
34-
<severity>0</severity>
35-
</rule>
36-
<rule ref="Generic.Commenting.DocComment.TagValueIndent">
37-
<severity>0</severity>
38-
</rule>
39-
<rule ref="Generic.Commenting.DocComment.ContentAfterOpen">
40-
<severity>0</severity>
41-
</rule>
42-
<rule ref="Generic.Commenting.DocComment.ContentBeforeClose">
43-
<severity>0</severity>
44-
</rule>
45-
<rule ref="Generic.Arrays.DisallowLongArraySyntax" />
4630
</ruleset>

public/index.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
require_once __DIR__ . '/../vendor/docusign/esign-client/autoload.php';
1111
require_once __DIR__ . '/../ds_config.php';
1212

13-
use Example\Services\RouterService;
13+
use DocuSign\Services\RouterService;
1414

1515
if (session_status() == PHP_SESSION_NONE) {
1616
session_start();
@@ -22,21 +22,29 @@
2222
$twig->addGlobal('app_url', $GLOBALS['app_url']);
2323
$twig->addGlobal('session', $_SESSION);
2424
$twig_function = new Twig\TwigFunction('get_flash', function () {
25-
if (! isset($_SESSION['flash'])) {$_SESSION['flash'] = [];}
25+
if (! isset($_SESSION['flash'])) {
26+
$_SESSION['flash'] = [];
27+
}
2628
$msgs = $_SESSION['flash'];
2729
$_SESSION['flash'] = [];
2830
return $msgs;
2931
});
3032
$twig->addFunction($twig_function);
3133
# Add csrf_token func. See https://stackoverflow.com/a/31683058/64904
32-
$twig_function = new Twig\TwigFunction('csrf_token', function($lock_to = null) {
33-
if (empty($_SESSION['csrf_token'])) {$_SESSION['csrf_token'] = bin2hex(random_bytes(32));}
34-
if (empty($_SESSION['csrf_token2'])) {$_SESSION['csrf_token2'] = random_bytes(32);}
35-
if (empty($lock_to)) {return $_SESSION['csrf_token'];}
34+
$twig_function = new Twig\TwigFunction('csrf_token', function ($lock_to = null) {
35+
if (empty($_SESSION['csrf_token'])) {
36+
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
37+
}
38+
if (empty($_SESSION['csrf_token2'])) {
39+
$_SESSION['csrf_token2'] = random_bytes(32);
40+
}
41+
if (empty($lock_to)) {
42+
return $_SESSION['csrf_token'];
43+
}
3644
return hash_hmac('sha256', $lock_to, $_SESSION['csrf_token2']);
3745
});
3846
$twig->addFunction($twig_function);
3947
$GLOBALS['twig'] = $twig;
4048
$router = new RouterService();
4149

42-
$router->router();
50+
$router->router();

0 commit comments

Comments
 (0)