Skip to content

Commit c35373c

Browse files
committed
Check docs
1 parent 2cdd437 commit c35373c

10 files changed

+113
-37
lines changed

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 <aydin@hotmail.co.uk>
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 <aydin@hotmail.co.uk>
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 it's 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 <aydin@hotmail.co.uk>
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 submission 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 submission.
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 submission, 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 <aydin@hotmail.co.uk>
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 submission.
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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
use Symfony\Component\Process\Process;
1717

1818
/**
19-
* Class DatabaseCheck
19+
* This check sets up a database and a `PDO` object. It prepends the database DSN as a CLI argument to the student's
20+
* solution so they can connect to the database. The PDO object is passed to the exercise before and after the
21+
* student's solution has been executed, allowing you to first seed the database and then verify the contents of the
22+
* database.
23+
*
2024
* @author Aydin Hassan <aydin@hotmail.co.uk>
2125
*/
2226
class DatabaseCheck implements ListenableCheckInterface
@@ -49,7 +53,7 @@ class DatabaseCheck implements ListenableCheckInterface
4953
private $solutionDsn;
5054

5155
/**
52-
*
56+
* Setup paths and DSN's.
5357
*/
5458
public function __construct()
5559
{
@@ -71,7 +75,6 @@ public function getName()
7175
}
7276

7377
/**
74-
*
7578
* @return string
7679
*/
7780
public function getExerciseInterface()
@@ -80,6 +83,9 @@ public function getExerciseInterface()
8083
}
8184

8285
/**
86+
* Here we attach to various events to seed, verify and inject the DSN's
87+
* to the student & reference solution programs's CLI arguments.
88+
*
8389
* @param EventDispatcher $eventDispatcher
8490
*/
8591
public function attach(EventDispatcher $eventDispatcher)

src/Check/FileExistsCheck.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99
use PhpSchool\PhpWorkshop\Result\Success;
1010

1111
/**
12-
* Class FileExistsCheck
12+
* This check verifies that the student's solution file actually exists.
13+
*
1314
* @package PhpSchool\PhpWorkshop\Check
1415
* @author Aydin Hassan <aydin@hotmail.co.uk>
1516
*/
1617
class FileExistsCheck implements SimpleCheckInterface
1718
{
1819
/**
20+
* Return the check's name
21+
*
1922
* @return string
2023
*/
2124
public function getName()
@@ -24,9 +27,11 @@ public function getName()
2427
}
2528

2629
/**
27-
* @param ExerciseInterface $exercise
28-
* @param string $fileName
29-
* @return ResultInterface
30+
* Simply check that the file exists.
31+
*
32+
* @param ExerciseInterface $exercise The exercise to check against.
33+
* @param string $fileName The absolute path to the student's submission.
34+
* @return ResultInterface The result of the check.
3035
*/
3136
public function check(ExerciseInterface $exercise, $fileName)
3237
{
@@ -38,6 +43,8 @@ public function check(ExerciseInterface $exercise, $fileName)
3843
}
3944

4045
/**
46+
* This check can run on any exercise type.
47+
*
4148
* @param ExerciseType $exerciseType
4249
* @return bool
4350
*/
@@ -56,6 +63,7 @@ public function getExerciseInterface()
5663
}
5764

5865
/**
66+
* This check must run before executing the solution becuase it may not exist.
5967
*
6068
* @return string
6169
*/

src/Check/FunctionRequirementsCheck.php

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

1818
/**
19-
* Class FunctionRequirementsCheck
19+
* This check verifies that the students submission contains usages of some required functions
20+
* and also does not use certain functions (specified by the exercise).
21+
*
2022
* @package PhpSchool\PhpWorkshop\Check
2123
* @author Aydin Hassan <aydin@hotmail.co.uk>
2224
*/
@@ -37,6 +39,8 @@ public function __construct(Parser $parser)
3739
}
3840

3941
/**
42+
* Return the check's name
43+
*
4044
* @return string
4145
*/
4246
public function getName()
@@ -45,9 +49,13 @@ public function getName()
4549
}
4650

4751
/**
48-
* @param ExerciseInterface $exercise
49-
* @param string $fileName
50-
* @return ResultInterface
52+
* Parse the students solution and check that there are usages of
53+
* required functions and that banned functions are not used. The requirements
54+
* are pulled from the exercise.
55+
*
56+
* @param ExerciseInterface $exercise The exercise to check against.
57+
* @param string $fileName The absolute path to the student's submission.
58+
* @return ResultInterface The result of the check.
5159
*/
5260
public function check(ExerciseInterface $exercise, $fileName)
5361
{
@@ -92,6 +100,8 @@ public function check(ExerciseInterface $exercise, $fileName)
92100
}
93101

94102
/**
103+
* This check can run on any exercise type.
104+
*
95105
* @param ExerciseType $exerciseType
96106
* @return bool
97107
*/
@@ -101,7 +111,6 @@ public function canRun(ExerciseType $exerciseType)
101111
}
102112

103113
/**
104-
*
105114
* @return string
106115
*/
107116
public function getExerciseInterface()
@@ -110,6 +119,9 @@ public function getExerciseInterface()
110119
}
111120

112121
/**
122+
* This is performed after executing the student's submission because the submission may produce the correct
123+
* output, but do it in a way that was not correct for the task. This way the student can see the program works
124+
* but missed some requirements.
113125
*
114126
* @return string
115127
*/

src/Check/ListenableCheckInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
interface ListenableCheckInterface extends CheckInterface
1313
{
1414
/**
15+
* Attach to events throughout the running/verifying process. Inject verifiers
16+
* and listeners.
17+
*
1518
* @param EventDispatcher $eventDispatcher
1619
*/
1720
public function attach(EventDispatcher $eventDispatcher);

0 commit comments

Comments
 (0)