Skip to content

Commit b9571f8

Browse files
committed
result docs
1 parent c05aa4f commit b9571f8

File tree

10 files changed

+122
-45
lines changed

10 files changed

+122
-45
lines changed

src/Result/CgiOutRequestFailure.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
use Psr\Http\Message\RequestInterface;
66

77
/**
8-
* Class CgiOutRequestFailure
8+
* A failure result representing the situation where the output of a student's solution did not match the
9+
* expected outcome in the context of a HTTP request.
10+
*
911
* @package PhpSchool\PhpWorkshop\Result
1012
* @author Aydin Hassan <aydin@hotmail.co.uk>
1113
*/
@@ -58,6 +60,8 @@ public function __construct(
5860
}
5961

6062
/**
63+
* Get the request object associated with this failure.
64+
*
6165
* @return RequestInterface
6266
*/
6367
public function getRequest()
@@ -66,6 +70,8 @@ public function getRequest()
6670
}
6771

6872
/**
73+
* Is the output different?
74+
*
6975
* @return bool
7076
*/
7177
public function bodyDifferent()
@@ -74,6 +80,8 @@ public function bodyDifferent()
7480
}
7581

7682
/**
83+
* Are the headers different?
84+
*
7785
* @return bool
7886
*/
7987
public function headersDifferent()
@@ -82,6 +90,8 @@ public function headersDifferent()
8290
}
8391

8492
/**
93+
* Are the headers & body different?
94+
*
8595
* @return bool
8696
*/
8797
public function headersAndBodyDifferent()
@@ -90,6 +100,8 @@ public function headersAndBodyDifferent()
90100
}
91101

92102
/**
103+
* Get the expected output.
104+
*
93105
* @return string
94106
*/
95107
public function getExpectedOutput()
@@ -98,6 +110,8 @@ public function getExpectedOutput()
98110
}
99111

100112
/**
113+
* Get the actual output.
114+
*
101115
* @return string
102116
*/
103117
public function getActualOutput()
@@ -106,6 +120,8 @@ public function getActualOutput()
106120
}
107121

108122
/**
123+
* Get the array of expected headers.
124+
*
109125
* @return array
110126
*/
111127
public function getExpectedHeaders()
@@ -114,6 +130,8 @@ public function getExpectedHeaders()
114130
}
115131

116132
/**
133+
* Get the array of actual headers.
134+
*
117135
* @return array
118136
*/
119137
public function getActualHeaders()

src/Result/CgiOutResult.php

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

33
namespace PhpSchool\PhpWorkshop\Result;
44

5-
use PhpSchool\PhpWorkshop\Check\CheckInterface;
65
use PhpSchool\PhpWorkshop\ResultAggregator;
76

87
/**
9-
* Class CgiOutFailure
8+
* A result which encompasses all the results for each individual request made during
9+
* the CGI verification process.
10+
*
1011
* @package PhpSchool\PhpWorkshop\Result
1112
* @author Aydin Hassan <aydin@hotmail.co.uk>
1213
*/
@@ -18,8 +19,8 @@ class CgiOutResult extends ResultAggregator implements ResultInterface
1819
private $name;
1920

2021
/**
21-
* @param string $name
22-
* @param array $requestResults
22+
* @param string $name The name of the check that produced this result.
23+
* @param array $requestResults An array of results representing each request.
2324
*/
2425
public function __construct($name, array $requestResults)
2526
{
@@ -31,6 +32,8 @@ public function __construct($name, array $requestResults)
3132

3233

3334
/**
35+
* Get the name of the check that this result was produced from, most likely the CGI Runner.
36+
*
3437
* @return string
3538
*/
3639
public function getCheckName()

src/Result/Failure.php

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
use PhpSchool\PhpWorkshop\Exception\CodeExecutionException;
88

99
/**
10-
* Class Failure
10+
* Default implementation of `PhpSchool\PhpWorkshop\Result\FailureInterface`.
11+
*
1112
* @package PhpSchool\PhpWorkshop
1213
* @author Aydin Hassan <aydin@hotmail.co.uk>
1314
*/
@@ -24,8 +25,11 @@ class Failure implements FailureInterface
2425
private $name;
2526

2627
/**
27-
* @param string $name
28-
* @param string|null $reason
28+
* Create an instance from the name of the check that produces this result
29+
* and the reason for the failure.
30+
*
31+
* @param string $name The name of the check that produced this result.
32+
* @param string|null $reason The reason (if any) of the failure.
2933
*/
3034
public function __construct($name, $reason = null)
3135
{
@@ -34,40 +38,49 @@ public function __construct($name, $reason = null)
3438
}
3539

3640
/**
37-
* @param string $name
38-
* @param $reason
39-
* @return static
41+
* Named constructor, for added code legibility.
42+
*
43+
* @param string $name The name of the check that produced this result.
44+
* @param string|null $reason The reason (if any) of the failure.
45+
* @return static The result.
4046
*/
4147
public static function fromNameAndReason($name, $reason)
4248
{
4349
return new static($name, $reason);
4450
}
4551

4652
/**
47-
* @param CheckInterface $check
48-
* @param string $reason
49-
* @return static
53+
* Static constructor to create from an instance of `PhpSchool\PhpWorkshop\Check\CheckInterface`.
54+
*
55+
* @param CheckInterface $check The check instance.
56+
* @param string $reason The reason (if any) of the failure.
57+
* @return static The result.
5058
*/
5159
public static function fromCheckAndReason(CheckInterface $check, $reason)
5260
{
5361
return new static($check->getName(), $reason);
5462
}
5563

5664
/**
57-
* @param string $name
58-
* @param CodeExecutionException $e
59-
* @return static
65+
* Static constructor to create from a `PhpSchool\PhpWorkshop\Exception\CodeExecutionException` exception.
66+
*
67+
* @param string $name The name of the check that produced this result.
68+
* @param CodeExecutionException $e The exception.
69+
* @return static The result.
6070
*/
6171
public static function fromNameAndCodeExecutionFailure($name, CodeExecutionException $e)
6272
{
6373
return new static($name, $e->getMessage());
6474
}
6575

6676
/**
67-
* @param CheckInterface $check
68-
* @param ParseErrorException $e
69-
* @param string $file
70-
* @return static
77+
* Static constructor to create from a `PhpParser\Error` exception. Many checks will need to parse the student's
78+
* solution, so this serves as a helper to create a consistent failure.
79+
*
80+
* @param CheckInterface $check The check that attempted to parse the solution.
81+
* @param ParseErrorException $e The parse exception.
82+
* @param string $file The absolute path to the solution.
83+
* @return static The result.
7184
*/
7285
public static function fromCheckAndCodeParseFailure(CheckInterface $check, ParseErrorException $e, $file)
7386
{
@@ -78,6 +91,8 @@ public static function fromCheckAndCodeParseFailure(CheckInterface $check, Parse
7891
}
7992

8093
/**
94+
* Get the name of the check that this result was produced from.
95+
*
8196
* @return string
8297
*/
8398
public function getCheckName()
@@ -86,6 +101,8 @@ public function getCheckName()
86101
}
87102

88103
/**
104+
* Get the reason, or `null` if there is no reason.
105+
*
89106
* @return string|null
90107
*/
91108
public function getReason()

src/Result/FailureInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
namespace PhpSchool\PhpWorkshop\Result;
44

55
/**
6-
* Interface FailureInterface
6+
* This interface represents a failure. Any result implementing this interface will
7+
* be treated as a failure.
8+
*
79
* @package PhpSchool\PhpWorkshop\Result
810
* @author Aydin Hassan <aydin@hotmail.co.uk>
911
*/

src/Result/FunctionRequirementsFailure.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
use PhpSchool\PhpWorkshop\Check\CheckInterface;
66

77
/**
8-
* Class FunctionRequirementsFailure
8+
* A failure result representing the situation where there were function usage requirements
9+
* and they were not met.
10+
*
911
* @package PhpSchool\PhpWorkshop\Result
1012
* @author Aydin Hassan <aydin@hotmail.co.uk>
1113
*/
@@ -24,9 +26,9 @@ class FunctionRequirementsFailure implements FailureInterface
2426
private $missingFunctions;
2527

2628
/**
27-
* @param CheckInterface $check
28-
* @param array $bannedFunctions
29-
* @param array $missingFunctions
29+
* @param CheckInterface $check The check that produced this result.
30+
* @param array $bannedFunctions A list of functions that were used, but were banned.
31+
* @param array $missingFunctions A list of functions that were not used, but were required.
3032
*/
3133
public function __construct(CheckInterface $check, array $bannedFunctions, array $missingFunctions)
3234
{
@@ -36,6 +38,8 @@ public function __construct(CheckInterface $check, array $bannedFunctions, array
3638
}
3739

3840
/**
41+
* Get the list of functions that were used, but were banned.
42+
*
3943
* @return array
4044
*/
4145
public function getBannedFunctions()
@@ -44,6 +48,8 @@ public function getBannedFunctions()
4448
}
4549

4650
/**
51+
* Get the list of functions that were not used, but were required.
52+
*
4753
* @return array
4854
*/
4955
public function getMissingFunctions()

src/Result/ResultInterface.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
namespace PhpSchool\PhpWorkshop\Result;
44

55
/**
6-
* Interface ResultInterface
6+
* The base result interface, on it's own does not mean much, instead the
7+
* interfaces `PhpSchool\PhpWorkshop\Result\SuccessInterface` & `PhpSchool\PhpWorkshop\Result\FailureInterface` should be used.
8+
*
79
* @package PhpSchool\PhpWorkshop\Result
810
*/
911
interface ResultInterface
1012
{
1113
/**
14+
* Get the name of the check that this result was produced from.
15+
*
1216
* @return string
1317
*/
1418
public function getCheckName();

src/Result/ResultTrait.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
use PhpSchool\PhpWorkshop\Check\CheckInterface;
66

77
/**
8-
* Trait ResultTrait
8+
* Helper to proxy the `getCheckName()` method through to the `PhpSchool\PhpWorkshop\Check\CheckInterface`
9+
* instance.
10+
*
911
* @package PhpSchool\PhpWorkshop\Result
1012
* @author Aydin Hassan <aydin@hotmail.co.uk>
1113
*/
@@ -17,6 +19,9 @@ trait ResultTrait
1719
private $check;
1820

1921
/**
22+
* Get the check name from the underlying check. Assumes that the `check` property has been
23+
* assigned an instance of `PhpSchool\PhpWorkshop\Check\CheckInterface`.
24+
*
2025
* @return string
2126
*/
2227
public function getCheckName()

src/Result/StdOutFailure.php

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
use PhpSchool\PhpWorkshop\Check\CheckInterface;
66

77
/**
8-
* Class StdOutFailure
8+
* A failure result representing the situation where the output of a solution does not match
9+
* that of the expected output.
10+
*
911
* @package PhpSchool\PhpWorkshop\Result
1012
* @author Aydin Hassan <aydin@hotmail.co.uk>
1113
*/
@@ -27,9 +29,9 @@ class StdOutFailure implements FailureInterface
2729
private $actualOutput;
2830

2931
/**
30-
* @param string $name
31-
* @param string $expectedOutput
32-
* @param string $actualOutput
32+
* @param string $name The name of the check that produced this result.
33+
* @param string $expectedOutput The expected output.
34+
* @param string $actualOutput The actual output.
3335
*/
3436
public function __construct($name, $expectedOutput, $actualOutput)
3537
{
@@ -39,28 +41,34 @@ public function __construct($name, $expectedOutput, $actualOutput)
3941
}
4042

4143
/**
42-
* @param string $name
43-
* @param $expectedOutput
44-
* @param $actualOutput
45-
* @return static
44+
* Named constructor, for added code legibility.
45+
*
46+
* @param string $name The name of the check that produced this result.
47+
* @param string $expectedOutput The expected output.
48+
* @param string $actualOutput The actual output.
49+
* @return static The result.
4650
*/
4751
public static function fromNameAndOutput($name, $expectedOutput, $actualOutput)
4852
{
4953
return new static($name, $expectedOutput, $actualOutput);
5054
}
5155

5256
/**
53-
* @param CheckInterface $check
54-
* @param $expectedOutput
55-
* @param $actualOutput
56-
* @return static
57+
* Static constructor to create from an instance of `PhpSchool\PhpWorkshop\Check\CheckInterface`.
58+
*
59+
* @param CheckInterface $check The check instance.
60+
* @param string $expectedOutput The expected output.
61+
* @param string $actualOutput The actual output.
62+
* @return static The result.
5763
*/
5864
public static function fromCheckAndOutput(CheckInterface $check, $expectedOutput, $actualOutput)
5965
{
6066
return new static($check->getName(), $expectedOutput, $actualOutput);
6167
}
6268

6369
/**
70+
* Get the name of the check that this result was produced from.
71+
*
6472
* @return string
6573
*/
6674
public function getCheckName()
@@ -69,6 +77,8 @@ public function getCheckName()
6977
}
7078

7179
/**
80+
* Get the expected output.
81+
*
7282
* @return string
7383
*/
7484
public function getExpectedOutput()
@@ -77,6 +87,8 @@ public function getExpectedOutput()
7787
}
7888

7989
/**
90+
* Get the actual output.
91+
*
8092
* @return string
8193
*/
8294
public function getActualOutput()

0 commit comments

Comments
 (0)