Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final changes #123

Merged
merged 33 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
53d3cf0
Implement some changes
dbhynds Dec 18, 2023
9590f42
Change a few more things
dbhynds Dec 18, 2023
2aa7074
Type a few things
dbhynds Dec 18, 2023
c83e288
A few more chagnes
dbhynds Dec 18, 2023
881b66c
Add code coverage
dbhynds Dec 18, 2023
e8e18db
Bump phpunit version
dbhynds Dec 18, 2023
7eaafac
Use xdebug maybe
dbhynds Dec 18, 2023
df33cce
Separate test
dbhynds Dec 18, 2023
ec64318
Simplify it
dbhynds Dec 18, 2023
d248598
Typo
dbhynds Dec 18, 2023
7394ef1
Don't use debug mode
dbhynds Dec 18, 2023
1503f82
Add badges
dbhynds Dec 18, 2023
ab54c47
On one line
dbhynds Dec 18, 2023
eeddd3a
Run tests weekly
dbhynds Dec 18, 2023
759e469
Abstract stuff
dbhynds Dec 18, 2023
8679ca0
Abstract stuff
dbhynds Dec 18, 2023
46e9f7e
Move deep link stuff
dbhynds Dec 18, 2023
92ff67f
Move has dimensions
dbhynds Dec 18, 2023
4678da0
Merge branch 'fix-todos' into final-changes
dbhynds Dec 18, 2023
7a66e36
Move objects again
dbhynds Dec 19, 2023
12c24af
Merge branch 'fix-todos' into final-changes
dbhynds Dec 19, 2023
5f464b9
Merge branch 'fix-todos' into final-changes
dbhynds Dec 19, 2023
0267ef0
Merge branch 'v6-deep-link' into final-changes
dbhynds Dec 19, 2023
b8e7f33
Add a helper to clean up arrayable
dbhynds Dec 19, 2023
d7482d7
Abstract null array filter
dbhynds Dec 19, 2023
d81abc8
Make Arrayable and Jsonable concerns
dbhynds Dec 19, 2023
b1e9cc7
Merge branch 'v6.0-beta' into final-changes
dbhynds Dec 19, 2023
2df843d
reorder methods
dbhynds Dec 19, 2023
d486058
Resolve some issues
dbhynds Dec 19, 2023
1a86e9e
Fix name
dbhynds Dec 19, 2023
08bb46e
Fix if
dbhynds Dec 19, 2023
8c4f412
Merge branch 'v6-deep-link' into final-changes
dbhynds Dec 19, 2023
9dea6df
Add missing interface method
dbhynds Dec 19, 2023
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
23 changes: 21 additions & 2 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
name: Tests & style checks
name: Tests & Style Checks
on:
# Trigger on any PR being opened, or on a merge to master (to update the badge)
# Trigger on any PR being opened
pull_request:
# Or weekly and on a merge to master (to update the badge)
push:
branches:
- master
schedule:
- cron: 0 0 * * 0
jobs:
lint:
name: Lint
Expand Down Expand Up @@ -34,3 +37,19 @@ jobs:
composer-options: "${{ matrix.composer-options }}"
- name: Run tests
run: composer test

coverage:
name: Code Coverage
runs-on: ubuntu-latest
steps:
- uses: "actions/checkout@v3"
- uses: "shivammathur/setup-php@v2"
with:
php-version: latest
coverage: xdebug
- uses: "ramsey/composer-install@v2"
- uses: paambaati/[email protected]
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
with:
coverageCommand: composer test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ tests/_support/_generated/*
vendor

# ignore the coverage folders
**/.phpunit.cache
**/coverage
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# LTI 1.3 Tool Library

![Test status](https://github.com/packbackbooks/lti-1-3-php-library/actions/workflows/run_tests.yml/badge.svg?branch=master)
![Test status](https://github.com/packbackbooks/lti-1-3-php-library/actions/workflows/run_tests.yml/badge.svg?branch=master) [![Maintainability](https://api.codeclimate.com/v1/badges/16055e83ea04ad95a2f9/maintainability)](https://codeclimate.com/github/packbackbooks/lti-1-3-php-library/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/16055e83ea04ad95a2f9/test_coverage)](https://codeclimate.com/github/packbackbooks/lti-1-3-php-library/test_coverage)

A library used for building IMS-certified LTI 1.3 tool providers in PHP.

Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"nesbot/carbon": "^2.43",
"laravel/pint": "^1.0",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.5"
"phpunit/phpunit": "^9.0|^10.0"
},
"autoload": {
"psr-4": {
Expand All @@ -43,11 +43,11 @@
}
},
"scripts": {
"test": [
"phpunit",
"test": "phpunit",
"lint": [
"pint --test",
"phpstan analyse"
],
"lint": "pint -v --test",
"lint-fix": "pint -v"
}
}
10 changes: 6 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage"/>
Expand All @@ -18,4 +15,9 @@
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
15 changes: 15 additions & 0 deletions src/Concerns/Arrayable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Packback\Lti1p3\Concerns;

use Packback\Lti1p3\Helpers\Helpers;

trait Arrayable
{
abstract public function getArray(): array;

public function toArray(): array
{
return Helpers::filterOutNulls($this->getArray());
}
}
13 changes: 13 additions & 0 deletions src/Concerns/JsonStringable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Packback\Lti1p3\Concerns;

trait JsonStringable
{
use Arrayable;

public function __toString(): string
{
return json_encode($this->toArray());
}
}
39 changes: 19 additions & 20 deletions src/DeepLinkResources/DateTimeInterval.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
namespace Packback\Lti1p3\DeepLinkResources;

use DateTime;
use Packback\Lti1p3\Concerns\Arrayable;
use Packback\Lti1p3\LtiException;

class DateTimeInterval
{
use Arrayable;
public const ERROR_NO_START_OR_END = 'Either a start or end time must be specified.';
public const ERROR_START_GT_END = 'The start time cannot be greater than end time.';

Expand All @@ -22,6 +24,20 @@ public static function new(): self
return new DateTimeInterval();
}

public function getArray(): array
{
if (!isset($this->start) && !isset($this->end)) {
throw new LtiException(self::ERROR_NO_START_OR_END);
}

$this->validateStartAndEnd();

return [
'startDateTime' => $this->start?->format(DateTime::ATOM),
'endDateTime' => $this->end?->format(DateTime::ATOM),
];
}

public function setStart(?DateTime $start): self
{
$this->start = $start;
Expand All @@ -46,26 +62,9 @@ public function getEnd(): ?DateTime
return $this->end;
}

public function toArray(): array
{
if (!isset($this->start) && !isset($this->end)) {
throw new LtiException(self::ERROR_NO_START_OR_END);
}

$this->validateStartAndEnd();

$dateTimeInterval = [];

if (isset($this->start)) {
$dateTimeInterval['startDateTime'] = $this->start->format(DateTime::ATOM);
}
if (isset($this->end)) {
$dateTimeInterval['endDateTime'] = $this->end->format(DateTime::ATOM);
}

return $dateTimeInterval;
}

/**
* @throws LtiException
*/
private function validateStartAndEnd(): void
{
if (isset($this->start) && isset($this->end) && $this->start > $this->end) {
Expand Down
22 changes: 12 additions & 10 deletions src/DeepLinkResources/Icon.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace Packback\Lti1p3\DeepLinkResources;

use Packback\Lti1p3\Concerns\Arrayable;

class Icon
{
use HasDimensions;
use Arrayable, HasDimensions;

public function __construct(
private string $url,
Expand All @@ -18,6 +20,15 @@ public static function new(string $url, int $width, int $height): self
return new Icon($url, $width, $height);
}

public function getArray(): array
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing the getArray() is just how the model is returned? I was wondering why this was named so generically.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. I need something that builds the potential array of properties before sending in through the various concerns for processing. I settled on getArray() but am open to suggestions for a better way to name this.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine, I could understand what it was doing by just looking at the function.

{
return [
'url' => $this->url,
'width' => $this->width,
'height' => $this->height,
];
}

public function setUrl(string $url): self
{
$this->url = $url;
Expand All @@ -29,13 +40,4 @@ public function getUrl(): string
{
return $this->url;
}

public function toArray(): array
{
return [
'url' => $this->url,
'width' => $this->width,
'height' => $this->height,
];
}
}
30 changes: 12 additions & 18 deletions src/DeepLinkResources/Iframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace Packback\Lti1p3\DeepLinkResources;

use Packback\Lti1p3\Concerns\Arrayable;

class Iframe
{
use HasDimensions;
use Arrayable, HasDimensions;

public function __construct(
private ?string $src = null,
Expand All @@ -18,6 +20,15 @@ public static function new(): self
return new Iframe();
}

public function getArray(): array
{
return [
'width' => $this->width,
'height' => $this->height,
'src' => $this->src,
];
}

public function setSrc(?string $src): self
{
$this->src = $src;
Expand All @@ -29,21 +40,4 @@ public function getSrc(): ?string
{
return $this->src;
}

public function toArray(): array
{
$iframe = [];

if (isset($this->width)) {
$iframe['width'] = $this->width;
}
if (isset($this->height)) {
$iframe['height'] = $this->height;
}
if (isset($this->src)) {
$iframe['src'] = $this->src;
}

return $iframe;
}
}
92 changes: 38 additions & 54 deletions src/DeepLinkResources/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace Packback\Lti1p3\DeepLinkResources;

use Packback\Lti1p3\Concerns\Arrayable;
use Packback\Lti1p3\LtiConstants;
use Packback\Lti1p3\LtiLineitem;

class Resource
{
use Arrayable;
private string $type = LtiConstants::DL_RESOURCE_LINK_TYPE;
private ?string $title = null;
private ?string $text = null;
Expand All @@ -26,6 +28,42 @@ public static function new(): self
return new Resource();
}

public function getArray(): array
{
$resource = [
'type' => $this->type,
'title' => $this->title,
'text' => $this->text,
'url' => $this->url,
'icon' => $this->icon?->toArray(),
'thumbnail' => $this->thumbnail?->toArray(),
'iframe' => $this->iframe?->toArray(),
'window' => $this->window?->toArray(),
'available' => $this->availability_interval?->toArray(),
'submission' => $this->submission_interval?->toArray(),
];

if (!empty($this->custom_params)) {
$resource['custom'] = $this->custom_params;
}

if (isset($this->line_item)) {
$resource['lineItem'] = [
'scoreMaximum' => $this->line_item->getScoreMaximum(),
'label' => $this->line_item->getLabel(),
];
}

// Kept for backwards compatibility
if (!isset($this->iframe) && !isset($this->window)) {
$resource['presentation'] = [
'documentTarget' => $this->target,
];
}

return $resource;
}

public function getType(): string
{
return $this->type;
Expand Down Expand Up @@ -169,58 +207,4 @@ public function setSubmissionInterval(?DateTimeInterval $submissionInterval): se

return $this;
}

public function toArray(): array
{
$resource = [
'type' => $this->type,
];

if (isset($this->title)) {
$resource['title'] = $this->title;
}
if (isset($this->text)) {
$resource['text'] = $this->text;
}
if (isset($this->url)) {
$resource['url'] = $this->url;
}
if (!empty($this->custom_params)) {
$resource['custom'] = $this->custom_params;
}
if (isset($this->icon)) {
$resource['icon'] = $this->icon->toArray();
}
if (isset($this->thumbnail)) {
$resource['thumbnail'] = $this->thumbnail->toArray();
}
if ($this->line_item !== null) {
$resource['lineItem'] = [
'scoreMaximum' => $this->line_item->getScoreMaximum(),
'label' => $this->line_item->getLabel(),
];
}

// Kept for backwards compatibility
if (!isset($this->iframe) && !isset($this->window)) {
$resource['presentation'] = [
'documentTarget' => $this->target,
];
}

if (isset($this->iframe)) {
$resource['iframe'] = $this->iframe->toArray();
}
if (isset($this->window)) {
$resource['window'] = $this->window->toArray();
}
if (isset($this->availability_interval)) {
$resource['available'] = $this->availability_interval->toArray();
}
if (isset($this->submission_interval)) {
$resource['submission'] = $this->submission_interval->toArray();
}

return $resource;
}
}
Loading