Skip to content

Commit ff2bf12

Browse files
committed
Exercise docs
1 parent 2c35851 commit ff2bf12

File tree

7 files changed

+76
-15
lines changed

7 files changed

+76
-15
lines changed

src/Exercise/AbstractExercise.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,29 @@
88
use ReflectionClass;
99

1010
/**
11-
* Class AbstractExercise
11+
* This abstract class implements many of the methods described in `\PhpSchool\PhpWorkshop\Exercise\ExerciseInterface`.
12+
* It serves as a good base for an exercise, providing useful defaults for many of the methods.
13+
*
1214
* @package PhpSchool\PhpWorkshop\Exercise
1315
* @author Aydin Hassan <aydin@hotmail.co.uk>
1416
*/
1517
abstract class AbstractExercise
1618
{
1719

1820
/**
21+
* Get the name of the exercise, like `Hello World!`.
22+
*
1923
* @return string
2024
*/
2125
abstract public function getName();
2226

2327
/**
28+
* This returns a single file solution named `solution.php` which
29+
* should exist in `workshop-root/exercises/<exercise-name>/solution/`.
30+
*
31+
* This method can be overwritten if the solution consists of multiple files,
32+
* see [Directory Solution](https://www.phpschool.io/docs/reference/exercise-solutions#directory-solution) for more details.
33+
*
2434
* @return SolutionInterface
2535
*/
2636
public function getSolution()
@@ -37,6 +47,9 @@ public function getSolution()
3747
}
3848

3949
/**
50+
* This returns the problem file path, which is assumed to exist in
51+
* `workshop-root/exercises/<exercise-name>/problem/` as a file named `problem.md`.
52+
*
4053
* @return string
4154
*/
4255
public function getProblem()
@@ -47,7 +60,10 @@ public function getProblem()
4760
}
4861

4962
/**
50-
* @return null
63+
* Allows to perform some cleanup after the exercise solution's have been executed, for example
64+
* remove files, close DB connections.
65+
*
66+
* @return void
5167
*/
5268
public function tearDown()
5369
{
@@ -63,6 +79,9 @@ private function normaliseName($name)
6379
}
6480

6581
/**
82+
* This method is implemented as empty by default, if you want to add additional checks or listen
83+
* to events, you should override this method.
84+
*
6685
* @param ExerciseDispatcher $dispatcher
6786
*/
6887
public function configure(ExerciseDispatcher $dispatcher)

src/Exercise/CgiExercise.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55
use Psr\Http\Message\RequestInterface;
66

77
/**
8-
* Interface CgiExercise
8+
* This interface describes the additional methods a CGI type exercise should implement.
9+
*
910
* @package PhpSchool\PhpWorkshop\Exercise
1011
*/
1112
interface CgiExercise
1213
{
1314
/**
14-
* @return RequestInterface[]
15+
* This method should return an array of PSR-7 requests, which will be forwarded to the student's
16+
* solution.
17+
*
18+
* @return RequestInterface[] An array of PSR-7 requests.
1519
*/
1620
public function getRequests();
1721
}

src/Exercise/CliExercise.php

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

33
namespace PhpSchool\PhpWorkshop\Exercise;
44

5-
use Psr\Http\Message\RequestInterface;
6-
75
/**
8-
* Interface CliExercise
6+
* This interface describes the additional methods a CLI type exercise should implement.
7+
*
98
* @package PhpSchool\PhpWorkshop\Exercise
109
*/
1110
interface CliExercise
1211
{
1312
/**
14-
* @return string[]
13+
* This method should return an array of strings which will be passed to the student's solution
14+
* as command line arguments.
15+
*
16+
* @return string[] An array of string arguments.
1517
*/
1618
public function getArgs();
1719
}

src/Exercise/ExerciseInterface.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,64 @@
66
use PhpSchool\PhpWorkshop\Solution\SolutionInterface;
77

88
/**
9-
* Class ExerciseInterface
9+
* This interface describes all of the methods an exercise
10+
* should implement.
11+
*
1012
* @package PhpSchool\PhpWorkshop\Exercise
1113
* @author Aydin Hassan <aydin@hotmail.co.uk>
1214
*/
13-
1415
interface ExerciseInterface
1516
{
1617

1718
/**
19+
* Get the name of the exercise, like `Hello World!`.
20+
*
1821
* @return string
1922
*/
2023
public function getName();
2124

2225
/**
26+
* Return the type of exercise. This is an ENUM. See `PhpSchool\PhpWorkshop\Exercise\ExerciseType`.
27+
*
2328
* @return ExerciseType
2429
*/
2530
public function getType();
2631

2732
/**
33+
* This is where the exercise specifies the extra checks it may require. It is also
34+
* possible to grab the even dispatcher from the exercise dispatcher and listen to any
35+
* events. This method is automatically invoked just before verifying/running an student's solution
36+
* to an exercise.
37+
*
2838
* @param ExerciseDispatcher $dispatcher
2939
*/
3040
public function configure(ExerciseDispatcher $dispatcher);
3141

3242
/**
43+
* A short description of the exercise.
44+
*
3345
* @return string
3446
*/
3547
public function getDescription();
3648

3749
/**
50+
* Get the exercise solution.
51+
*
3852
* @return SolutionInterface
3953
*/
4054
public function getSolution();
4155

4256
/**
57+
* Get the absolute path to the markdown file which contains the exercise problem.
58+
*
4359
* @return string
4460
*/
4561
public function getProblem();
4662

4763
/**
64+
* Allows to perform some cleanup after the exercise solution's have been executed, for example
65+
* remove files, close DB connections.
66+
*
4867
* @return void
4968
*/
5069
public function tearDown();

src/Exercise/ExerciseType.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
use PhpSchool\PhpWorkshop\ExerciseRunner\CliRunner;
88

99
/**
10-
* Class ExerciseType
10+
* This class is a ENUM which represents the types that exercises can be. Instantiation looks like:
11+
*
12+
* ```php
13+
* $typeCli = ExerciseType::CLI();
14+
* $typeCgi = ExerciseType::CGI();
15+
* ```
16+
*
1117
* @package PhpSchool\PhpWorkshop\Exercise
1218
* @author Aydin Hassan <aydin@hotmail.co.uk>
1319
*/

src/Exercise/SubmissionPatchable.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@
55
use PhpSchool\PhpWorkshop\Patch;
66

77
/**
8-
* Interface SubmissionPatchable
8+
* This interface, when implemented by an exercise, tells the workshop framework that the exercise
9+
* would like to patch the student's submission. This might include adding code to the top of the file like
10+
* injecting variables. The exercise should implement the `getPatch()` method and it should return a `Patch`.
11+
* See [Patching Exercise Submissions](https://www.phpschool.io/docs/reference/patching-exercise-solutions) for more details.
12+
*
913
* @package PhpSchool\PhpWorkshop\Exercise
1014
* @author Aydin Hassan <aydin@hotmail.co.uk>
1115
*/
1216
interface SubmissionPatchable
1317
{
1418
/**
19+
* Get the patch.
20+
*
1521
* @return Patch
1622
*/
1723
public function getPatch();

src/Exercise/TemporaryDirectoryTrait.php

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

55
/**
6-
* Class TemporaryDirectoryTrait
6+
* Helper trait to use in exercises to get a temporary path
7+
* for IO stuff.
8+
*
79
* @package PhpSchool\PhpWorkshop\Exercise
810
* @author Aydin Hassan <aydin@hotmail.co.uk>
911
*/
1012
trait TemporaryDirectoryTrait
1113
{
1214
/**
13-
* @return string
15+
* Get a temporary directory to use in exercises, takes in to account
16+
* the class-name.
17+
*
18+
* @return string The absolute path to the temporary directory.
1419
*/
15-
protected function getTemporaryPath()
20+
public function getTemporaryPath()
1621
{
1722
return sprintf(
1823
'%s/%s',

0 commit comments

Comments
 (0)