Skip to content

Commit 17b5818

Browse files
authored
Merge pull request #120 from php-school/api-docs
Api docs
2 parents 7e86d5c + 6ef08e7 commit 17b5818

File tree

77 files changed

+1007
-308
lines changed

Some content is hidden

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

77 files changed

+1007
-308
lines changed

composer.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@
5353
}
5454
},
5555
"scripts" : {
56-
"test": [
57-
"phpunit",
58-
"@cs"
59-
],
6056
"cs" : [
6157
"phpcs src --standard=PSR2",
6258
"phpcs test --standard=PSR2"

src/Application.php

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44

55
use Assert\Assertion;
66
use DI\ContainerBuilder;
7-
use PhpSchool\PhpWorkshop\Check\CheckInterface;
87
use PhpSchool\PhpWorkshop\Check\CheckRepository;
98
use PhpSchool\PhpWorkshop\Exception\MissingArgumentException;
109
use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface;
1110
use PhpSchool\PhpWorkshop\Factory\ResultRendererFactory;
1211
use PhpSchool\PhpWorkshop\Output\OutputInterface;
13-
use PhpSchool\PhpWorkshop\ResultRenderer\ResultRendererInterface;
1412

1513
/**
16-
* Class Application
14+
* This is the main application class, this takes care of bootstrapping, routing and
15+
* output.
16+
*
1717
* @package PhpSchool\PhpWorkshop
1818
* @author Aydin Hassan <[email protected]>
1919
*/
@@ -45,7 +45,7 @@ final class Application
4545
private $diConfigFile;
4646

4747
/**
48-
* @var string
48+
* @var string|null
4949
*/
5050
private $logo = null;
5151

@@ -60,8 +60,11 @@ final class Application
6060
private $bgColour = 'black';
6161

6262
/**
63-
* @param string $workshopTitle
64-
* @param $diConfigFile
63+
* It should be instantiated with the title of
64+
* the workshop and the path to the DI configuration file.
65+
*
66+
* @param string $workshopTitle The workshop title - this is used throughout the application
67+
* @param string $diConfigFile The absolute path to the DI configuration file
6568
*/
6669
public function __construct($workshopTitle, $diConfigFile)
6770
{
@@ -73,15 +76,21 @@ public function __construct($workshopTitle, $diConfigFile)
7376
}
7477

7578
/**
76-
* @param string $check
79+
* Register a custom check with the application. Exercises will only be able to use the check
80+
* if it has been registered here.
81+
*
82+
* @param string $check The FQCN of the check
7783
*/
7884
public function addCheck($check)
7985
{
8086
$this->checks[] = $check;
8187
}
8288

8389
/**
84-
* @param string $exercise
90+
* Register an exercise with the application. Only exercises registered here will
91+
* be displayed in the exercise menu.
92+
*
93+
* @param string $exercise The FQCN of the check
8594
*/
8695
public function addExercise($exercise)
8796
{
@@ -104,7 +113,10 @@ public function addResult($resultClass, $resultRendererClass)
104113
}
105114

106115
/**
107-
* @param string $logo
116+
* Add an ASCII art logo to the application. This will be displayed at the top of them menu. It will be
117+
* automatically padded to sit in the middle.
118+
*
119+
* @param string $logo The logo
108120
*/
109121
public function setLogo($logo)
110122
{
@@ -113,7 +125,10 @@ public function setLogo($logo)
113125
}
114126

115127
/**
116-
* @param string $colour
128+
* Modify the foreground color of the workshop menu
129+
* Can be any of: black, red, green, yellow, blue, magenta, cyan, white
130+
*
131+
* @param string $colour The colour
117132
*/
118133
public function setFgColour($colour)
119134
{
@@ -122,7 +137,10 @@ public function setFgColour($colour)
122137
}
123138

124139
/**
125-
* @param string $colour
140+
* Modify the background color of the workshop menu
141+
* Can be any of: black, red, green, yellow, blue, magenta, cyan, white
142+
*
143+
* @param string $colour The colour
126144
*/
127145
public function setBgColour($colour)
128146
{
@@ -131,7 +149,10 @@ public function setBgColour($colour)
131149
}
132150

133151
/**
134-
* Run the app
152+
* Executes the framework, invoking the specified command.
153+
* The return value is the exit code. 0 for success, anything else is a failure.
154+
*
155+
* @return int The exit code
135156
*/
136157
public function run()
137158
{

src/Check/CheckInterface.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
namespace PhpSchool\PhpWorkshop\Check;
44

55
/**
6-
* Class CheckInterface
6+
* Base Interface for Checks.
7+
*
78
* @package PhpSchool\PhpWorkshop\Comparator
89
* @author Aydin Hassan <[email protected]>
910
*/
@@ -18,7 +19,7 @@ public function getName();
1819

1920
/**
2021
* This returns the interface the exercise should implement
21-
* when requiring this check
22+
* when requiring this check. It should be the FQCN of the interface.
2223
*
2324
* @return string
2425
*/

src/Check/CheckRepository.php

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

33
namespace PhpSchool\PhpWorkshop\Check;
44

5-
use PhpSchool\CliMenu\Exception\InvalidTerminalException;
65
use PhpSchool\PhpWorkshop\Exception\InvalidArgumentException;
76

87
/**
9-
* Class CheckRepository
8+
* This class is the repository containing all the available checks
9+
* for the workshop framework.
10+
*
1011
* @package PhpSchool\PhpWorkshop\Check
1112
* @author Aydin Hassan <[email protected]>
1213
*/
@@ -18,7 +19,7 @@ class CheckRepository
1819
private $checks = [];
1920

2021
/**
21-
* @param CheckInterface[] $checks
22+
* @param CheckInterface[] $checks An array of checks available to the workshop framework.
2223
*/
2324
public function __construct(array $checks = [])
2425
{
@@ -28,14 +29,18 @@ public function __construct(array $checks = [])
2829
}
2930

3031
/**
31-
* @param CheckInterface $check
32+
* Add a new check to the repository.
33+
*
34+
* @param CheckInterface $check The check instance to add.
3235
*/
3336
public function registerCheck(CheckInterface $check)
3437
{
3538
$this->checks[get_class($check)] = $check;
3639
}
3740

3841
/**
42+
* Get all of the checks in the repository.
43+
*
3944
* @return array
4045
*/
4146
public function getAll()
@@ -44,9 +49,11 @@ public function getAll()
4449
}
4550

4651
/**
47-
* @param string $class
48-
* @return CheckInterface
49-
* @throws InvalidArgumentException
52+
* Get a check instance via it's class name.
53+
*
54+
* @param string $class The class name of the check instance.
55+
* @return CheckInterface The instance.
56+
* @throws InvalidArgumentException If an instance of the check does not exist.
5057
*/
5158
public function getByClass($class)
5259
{
@@ -58,6 +65,8 @@ public function getByClass($class)
5865
}
5966

6067
/**
68+
* Query whether a check instance exists in this repository via its class name.
69+
*
6170
* @param string $class
6271
* @return bool
6372
*/

src/Check/CodeParseCheck.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
use PhpSchool\PhpWorkshop\Result\Success;
1414

1515
/**
16-
* Class CodeParseCheck
16+
* This check attempts to parse a student's solution and returns
17+
* a success or failure based on the result of the parsing.
18+
*
1719
* @package PhpSchool\PhpWorkshop\Check
1820
* @author Aydin Hassan <[email protected]>
1921
*/
@@ -34,6 +36,8 @@ public function __construct(Parser $parser)
3436
}
3537

3638
/**
39+
* Return the check's name
40+
*
3741
* @return string
3842
*/
3943
public function getName()
@@ -42,9 +46,13 @@ public function getName()
4246
}
4347

4448
/**
45-
* @param ExerciseInterface $exercise
46-
* @param string $fileName
47-
* @return ResultInterface
49+
* This check grabs the contents of the student's solution and
50+
* attempts to parse it with `nikic/php-parser`. If any exceptions are thrown
51+
* by the parser, it is treated as a failure.
52+
*
53+
* @param ExerciseInterface $exercise The exercise to check against.
54+
* @param string $fileName The absolute path to the student's solution.
55+
* @return ResultInterface The result of the check.
4856
*/
4957
public function check(ExerciseInterface $exercise, $fileName)
5058
{
@@ -61,6 +69,8 @@ public function check(ExerciseInterface $exercise, $fileName)
6169
}
6270

6371
/**
72+
* This check can run on any exercise type.
73+
*
6474
* @param ExerciseType $exerciseType
6575
* @return bool
6676
*/
@@ -70,7 +80,6 @@ public function canRun(ExerciseType $exerciseType)
7080
}
7181

7282
/**
73-
*
7483
* @return string
7584
*/
7685
public function getExerciseInterface()
@@ -79,6 +88,8 @@ public function getExerciseInterface()
7988
}
8089

8190
/**
91+
* This check should be run before executing the student's solution, as, if it cannot be parsed
92+
* it probably cannot be executed.
8293
*
8394
* @return string
8495
*/

src/Check/ComposerCheck.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@
1111
use PhpSchool\PhpWorkshop\Result\Success;
1212

1313
/**
14-
* Class ComposerCheck
14+
* This check looks for a set of composer packages specified by the exercise
15+
* in the students `composer.lock` file.
16+
*
1517
* @author Aydin Hassan <[email protected]>
1618
*/
1719
class ComposerCheck implements SimpleCheckInterface
1820
{
1921

2022
/**
23+
* Return the check's name
24+
*
2125
* @return string
2226
*/
2327
public function getName()
@@ -26,9 +30,13 @@ public function getName()
2630
}
2731

2832
/**
29-
* @param ExerciseInterface $exercise
30-
* @param string $fileName
31-
* @return ResultInterface
33+
* This check parses the `composer.lock` file and checks that the student
34+
* installed a set of required packages. If they did not a failure is returned, otherwise,
35+
* a success is returned.
36+
*
37+
* @param ExerciseInterface $exercise The exercise to check against.
38+
* @param string $fileName The absolute path to the student's solution.
39+
* @return ResultInterface The result of the check.
3240
*/
3341
public function check(ExerciseInterface $exercise, $fileName)
3442
{
@@ -63,6 +71,8 @@ public function check(ExerciseInterface $exercise, $fileName)
6371
}
6472

6573
/**
74+
* This check can run on any exercise type.
75+
*
6676
* @param ExerciseType $exerciseType
6777
* @return bool
6878
*/
@@ -81,6 +91,7 @@ public function getExerciseInterface()
8191
}
8292

8393
/**
94+
* This check can run before because if it fails, there is no point executing the solution.
8495
*
8596
* @return string
8697
*/

src/Check/DatabaseCheck.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@
77
use PhpSchool\PhpWorkshop\Event\CliExecuteEvent;
88
use PhpSchool\PhpWorkshop\Event\Event;
99
use PhpSchool\PhpWorkshop\Event\EventDispatcher;
10-
use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface;
11-
use PhpSchool\PhpWorkshop\Exercise\ExerciseType;
1210
use PhpSchool\PhpWorkshop\Exercise\TemporaryDirectoryTrait;
1311
use PhpSchool\PhpWorkshop\ExerciseCheck\DatabaseExerciseCheck;
1412
use PhpSchool\PhpWorkshop\Result\Failure;
1513
use PhpSchool\PhpWorkshop\Result\Success;
1614
use Symfony\Component\Process\Process;
1715

1816
/**
19-
* Class DatabaseCheck
17+
* This check sets up a database and a `PDO` object. It prepends the database DSN as a CLI argument to the student's
18+
* solution so they can connect to the database. The `PDO` object is passed to the exercise before and after the
19+
* student's solution has been executed, allowing you to first seed the database and then verify the contents of the
20+
* database.
21+
*
2022
* @author Aydin Hassan <[email protected]>
2123
*/
2224
class DatabaseCheck implements ListenableCheckInterface
@@ -49,7 +51,7 @@ class DatabaseCheck implements ListenableCheckInterface
4951
private $solutionDsn;
5052

5153
/**
52-
*
54+
* Setup paths and DSN's.
5355
*/
5456
public function __construct()
5557
{
@@ -71,7 +73,6 @@ public function getName()
7173
}
7274

7375
/**
74-
*
7576
* @return string
7677
*/
7778
public function getExerciseInterface()
@@ -80,6 +81,9 @@ public function getExerciseInterface()
8081
}
8182

8283
/**
84+
* Here we attach to various events to seed, verify and inject the DSN's
85+
* to the student & reference solution programs's CLI arguments.
86+
*
8387
* @param EventDispatcher $eventDispatcher
8488
*/
8589
public function attach(EventDispatcher $eventDispatcher)

0 commit comments

Comments
 (0)