Skip to content

Commit

Permalink
Merge pull request #94 from packbackbooks/fix-linter
Browse files Browse the repository at this point in the history
Fix linting and tests
  • Loading branch information
dbhynds authored Jun 20, 2023
2 parents 8284acd + 1f11745 commit a6a4a87
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 59 deletions.
32 changes: 5 additions & 27 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,20 @@

require __DIR__.'/vendor/autoload.php';

return (new \Jubeki\LaravelCodeStyle\Config())
return (new Jubeki\LaravelCodeStyle\Config())
->setFinder(
\PhpCsFixer\Finder::create()
->ignoreVCS(true)
->ignoreVCSIgnored(true)
->in(__DIR__)
)
->setRules([
'@Symfony' => true,
'@Laravel' => true,

/* Packback-specific style preferences */
'not_operator_with_successor_space' => false,
'concat_space' => ['spacing' => 'one'],
'class_attributes_separation' => [
'elements' => [ 'property' => 'none' ],
],
'global_namespace_import' => [
'import_classes' => true,
'import_functions' => false,
],
'explicit_indirect_variable' => true,
'explicit_string_variable' => true,
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
'no_null_property_initialization' => true,
'ordered_class_elements' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_order' => true,
'phpdoc_order_by_value' => true,
'phpdoc_types_order' => true,
'phpdoc_var_annotation_correct_order' => true,
'return_assignment' => true,
'single_line_throw' => false,
'yoda_style' => [
'equal' => false,
'identical' => false,
'less_and_greater' => false,
'elements' => [
'const' => 'only_if_meta',
'property' => 'only_if_meta',
],
],
]);
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"phpseclib/phpseclib": "^3.0"
},
"require-dev": {
"jubeki/laravel-code-style": "^1.0",
"jubeki/laravel-code-style": "^1.0|^2.0",
"mockery/mockery": "^1.4",
"nesbot/carbon": "^2.43",
"phpunit/phpunit": "^9.5"
Expand Down
1 change: 1 addition & 0 deletions src/LtiConstants.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class LtiConstants
public const MEMBERSHIP_MANAGER = 'http://purl.imsglobal.org/vocab/lis/v2/membership#Manager';
public const MEMBERSHIP_MEMBER = 'http://purl.imsglobal.org/vocab/lis/v2/membership#Member';
public const MEMBERSHIP_OFFICER = 'http://purl.imsglobal.org/vocab/lis/v2/membership#Officer';

// Context sub-roles
public const MEMBERSHIP_EXTERNALINSTRUCTOR = 'http://purl.imsglobal.org/vocab/lis/v2/membership/Instructor#ExternalInstructor';
public const MEMBERSHIP_GRADER = 'http://purl.imsglobal.org/vocab/lis/v2/membership/Instructor#Grader';
Expand Down
28 changes: 12 additions & 16 deletions src/LtiMessageLaunch.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class LtiMessageLaunch
public const TYPE_DEEPLINK = 'LtiDeepLinkingRequest';
public const TYPE_SUBMISSIONREVIEW = 'LtiSubmissionReviewRequest';
public const TYPE_RESOURCELINK = 'LtiResourceLinkRequest';

public const ERR_FETCH_PUBLIC_KEY = 'Failed to fetch public key.';
public const ERR_NO_PUBLIC_KEY = 'Unable to find public key.';
public const ERR_NO_MATCHING_PUBLIC_KEY = 'Unable to find a public key which matches your JWT.';
Expand All @@ -36,7 +35,6 @@ class LtiMessageLaunch
* error message is built.
*/
public const ERR_MISSING_REGISTRATION = 'LTI 1.3 Registration not found for Issuer :issuerUrl and Client ID :clientId. Please make sure the LMS has provided the right information, and that the LMS has been registered correctly in the tool.';

public const ERR_CLIENT_NOT_REGISTERED = 'Client id not registered for this issuer.';
public const ERR_NO_KID = 'No KID specified in the JWT Header.';
public const ERR_INVALID_SIGNATURE = 'Invalid signature on id_token';
Expand All @@ -47,7 +45,6 @@ class LtiMessageLaunch
public const ERR_INVALID_MESSAGE = 'Message validation failed.';
public const ERR_INVALID_ALG = 'Invalid alg was specified in the JWT header.';
public const ERR_MISMATCHED_ALG_KEY = 'The alg specified in the JWT header is incompatible with the JWK key type.';

private $db;
private $cache;
private $cookie;
Expand All @@ -70,10 +67,10 @@ class LtiMessageLaunch
/**
* Constructor.
*
* @param IDatabase $database Instance of the database interface used for looking up registrations and deployments
* @param ICache $cache Instance of the Cache interface used to loading and storing launches
* @param ICookie $cookie Instance of the Cookie interface used to set and read cookies
* @param ILtiServiceConnector $serviceConnector Instance of the LtiServiceConnector used to by LTI services to make API requests
* @param IDatabase $database Instance of the database interface used for looking up registrations and deployments
* @param ICache $cache Instance of the Cache interface used to loading and storing launches
* @param ICookie $cookie Instance of the Cookie interface used to set and read cookies
* @param ILtiServiceConnector $serviceConnector Instance of the LtiServiceConnector used to by LTI services to make API requests
*/
public function __construct(
IDatabase $database,
Expand Down Expand Up @@ -105,13 +102,12 @@ public static function new(
/**
* Load an LtiMessageLaunch from a Cache using a launch id.
*
* @param string $launch_id The launch id of the LtiMessageLaunch object that is being pulled from the cache
* @param IDatabase $database Instance of the database interface used for looking up registrations and deployments
* @param ICache $cache Instance of the Cache interface used to loading and storing launches. If non is provided launch data will be store in $_SESSION.
* @param string $launch_id The launch id of the LtiMessageLaunch object that is being pulled from the cache
* @param IDatabase $database Instance of the database interface used for looking up registrations and deployments
* @param ICache $cache Instance of the Cache interface used to loading and storing launches. If non is provided launch data will be store in $_SESSION.
* @return LtiMessageLaunch A populated and validated LtiMessageLaunch
*
* @throws LtiException Will throw an LtiException if validation fails or launch cannot be found
*
* @return LtiMessageLaunch A populated and validated LtiMessageLaunch
*/
public static function fromCache(
$launch_id,
Expand All @@ -129,11 +125,10 @@ public static function fromCache(
/**
* Validates all aspects of an incoming LTI message launch and caches the launch if successful.
*
* @param array|string $request An array of post request parameters. If not set will default to $_POST.
* @param array|string $request An array of post request parameters. If not set will default to $_POST.
* @return LtiMessageLaunch Will return $this if validation is successful
*
* @throws LtiException Will throw an LtiException if validation fails
*
* @return LtiMessageLaunch Will return $this if validation is successful
*/
public function validate(array $request = null)
{
Expand Down Expand Up @@ -456,7 +451,8 @@ private function validateJwtSignature()

// Validate JWT signature
try {
JWT::decode($this->request['id_token'], $public_key, ['RS256']);
$headers = new \stdClass();
JWT::decode($this->request['id_token'], $public_key, $headers);
} catch (ExpiredException $e) {
// Error validating signature.
throw new LtiException(static::ERR_INVALID_SIGNATURE);
Expand Down
13 changes: 5 additions & 8 deletions src/LtiOidcLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,19 @@
class LtiOidcLogin
{
public const COOKIE_PREFIX = 'lti1p3_';

public const ERROR_MSG_LAUNCH_URL = 'No launch URL configured';
public const ERROR_MSG_ISSUER = 'Could not find issuer';
public const ERROR_MSG_LOGIN_HINT = 'Could not find login hint';

private $db;
private $cache;
private $cookie;

/**
* Constructor.
*
* @param IDatabase $database Instance of the Database interface used for looking up registrations and deployments
* @param ICache $cache instance of the Cache interface used to loading and storing launches
* @param ICookie $cookie instance of the Cookie interface used to set and read cookies
* @param IDatabase $database Instance of the Database interface used for looking up registrations and deployments
* @param ICache $cache instance of the Cache interface used to loading and storing launches
* @param ICookie $cookie instance of the Cookie interface used to set and read cookies
*/
public function __construct(IDatabase $database, ICache $cache = null, ICookie $cookie = null)
{
Expand All @@ -43,9 +41,8 @@ public static function new(IDatabase $database, ICache $cache = null, ICookie $c
/**
* Calculate the redirect location to return to based on an OIDC third party initiated login request.
*
* @param string $launch_url URL to redirect back to after the OIDC login. This URL must match exactly a URL white listed in the platform.
* @param array|string $request An array of request parameters. If not set will default to $_REQUEST.
*
* @param string $launch_url URL to redirect back to after the OIDC login. This URL must match exactly a URL white listed in the platform.
* @param array|string $request An array of request parameters. If not set will default to $_REQUEST.
* @return Redirect returns a redirect object containing the fully formed OIDC login URL
*/
public function doOidcLoginRedirect($launch_url, array $request = null)
Expand Down
1 change: 0 additions & 1 deletion src/LtiServiceConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
class LtiServiceConnector implements ILtiServiceConnector
{
public const NEXT_PAGE_REGEX = '/<([^>]*)>; ?rel="next"/i';

private $cache;
private $client;
private $debuggingMode = false;
Expand Down
5 changes: 4 additions & 1 deletion src/ServiceRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ class ServiceRequest implements IServiceRequest
// Request types
public const TYPE_UNSUPPORTED = 'unsupported';
public const TYPE_AUTH = 'auth';

// MessageLaunch
public const TYPE_GET_KEYSET = 'get_keyset';

// AGS
public const TYPE_GET_GRADES = 'get_grades';
public const TYPE_SYNC_GRADE = 'sync_grades';
Expand All @@ -25,12 +27,13 @@ class ServiceRequest implements IServiceRequest
public const TYPE_GET_LINEITEMS = 'get_lineitems';
public const TYPE_GET_LINEITEM = 'get_lineitem';
public const TYPE_UPDATE_LINEITEM = 'update_lineitem';

// CGS
public const TYPE_GET_GROUPS = 'get_groups';
public const TYPE_GET_SETS = 'get_sets';

// NRPS
public const TYPE_GET_MEMBERSHIPS = 'get_memberships';

private $method;
private $url;
private $type;
Expand Down
6 changes: 2 additions & 4 deletions tests/Certification/Lti13CertificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ class Lti13CertificationTest extends TestCase
public const JWKS_FILE = '/tmp/jwks.json';
public const CERT_DATA_DIR = __DIR__.'/../data/certification/';
public const PRIVATE_KEY = __DIR__.'/../data/private.key';

public const STATE = 'state';

private $issuer;
private $key;

Expand Down Expand Up @@ -403,7 +401,7 @@ public function testInvalidCertificationCases()
$this->assertInstanceOf(LtiException::class, $e);
}

++$testedCases;
$testedCases++;
}
echo PHP_EOL;
$this->assertEquals($casesCount, $testedCases);
Expand Down Expand Up @@ -458,7 +456,7 @@ public function testValidCertificationCases()
// Assertions
$this->assertInstanceOf(LtiMessageLaunch::class, $result);

++$testedCases;
$testedCases++;
}
echo PHP_EOL;
$this->assertEquals($casesCount, $testedCases);
Expand Down
1 change: 0 additions & 1 deletion tests/LtiMessageLaunchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class LtiMessageLaunchTest extends TestCase
public const JWKS_FILE = '/tmp/jwks.json';
public const CERT_DATA_DIR = __DIR__.'/data/certification/';
public const PRIVATE_KEY = __DIR__.'/data/private.key';

public const STATE = 'state';

public function setUp(): void
Expand Down

0 comments on commit a6a4a87

Please sign in to comment.