Skip to content

Commit 51ba7ff

Browse files
committed
result renderer docs
1 parent b9571f8 commit 51ba7ff

File tree

6 files changed

+56
-27
lines changed

6 files changed

+56
-27
lines changed

src/ResultRenderer/CgiOutResultRenderer.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
use PhpSchool\PhpWorkshop\Result\CgiOutResult;
77
use PhpSchool\PhpWorkshop\Result\FailureInterface;
88
use PhpSchool\PhpWorkshop\Result\ResultInterface;
9-
use PhpSchool\PhpWorkshop\Result\SuccessInterface;
109

1110
/**
12-
* Class CgiOutResultRenderer
11+
* Renderer for `PhpSchool\PhpWorkshop\Result\CgiOutResult`.
12+
*
1313
* @package PhpSchool\PhpWorkshop\ResultRenderer
1414
*/
1515
class CgiOutResultRenderer implements ResultRendererInterface
@@ -21,14 +21,16 @@ class CgiOutResultRenderer implements ResultRendererInterface
2121
private $result;
2222

2323
/**
24-
* @param CgiOutResult $result
24+
* @param CgiOutResult $result The result.
2525
*/
2626
public function __construct(CgiOutResult $result)
2727
{
2828
$this->result = $result;
2929
}
3030

3131
/**
32+
* Render the details of each failed request including the mismatching headers and body.
33+
*
3234
* @param ResultsRenderer $renderer
3335
* @return string
3436
*/

src/ResultRenderer/FailureRenderer.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
use PhpSchool\PhpWorkshop\Result\ResultInterface;
77

88
/**
9-
* Class FailureRenderer
9+
* Renderer for `PhpSchool\PhpWorkshop\Result\Failure`.
10+
*
1011
* @package PhpSchool\PhpWorkshop\ResultRenderer
1112
*/
1213
class FailureRenderer implements ResultRendererInterface
@@ -17,14 +18,16 @@ class FailureRenderer implements ResultRendererInterface
1718
private $result;
1819

1920
/**
20-
* @param Failure $result
21+
* @param Failure $result The failure.
2122
*/
2223
public function __construct(Failure $result)
2324
{
2425
$this->result = $result;
2526
}
2627

2728
/**
29+
* Simply print the reason.
30+
*
2831
* @param ResultsRenderer $renderer
2932
* @return string
3033
*/

src/ResultRenderer/FunctionRequirementsFailureRenderer.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
use PhpSchool\PhpWorkshop\Result\FunctionRequirementsFailure;
66

77
/**
8-
* Class FunctionRequirementsFailureRenderer
8+
* Renderer for `PhpSchool\PhpWorkshop\Result\FunctionRequirementsFailure`.
9+
*
910
* @package PhpSchool\PhpWorkshop\ResultRenderer
1011
* @author Aydin Hassan <aydin@hotmail.co.uk>
1112
*/
@@ -17,14 +18,16 @@ class FunctionRequirementsFailureRenderer implements ResultRendererInterface
1718
private $result;
1819

1920
/**
20-
* @param FunctionRequirementsFailure $result
21+
* @param FunctionRequirementsFailure $result The failure.
2122
*/
2223
public function __construct(FunctionRequirementsFailure $result)
2324
{
2425
$this->result = $result;
2526
}
2627

2728
/**
29+
* Print a list of the missing, required functions & print a list of used but banned functions.
30+
*
2831
* @param ResultsRenderer $renderer
2932
* @return string
3033
*/

src/ResultRenderer/OutputFailureRenderer.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
use PhpSchool\PhpWorkshop\Result\StdOutFailure;
77

88
/**
9-
* Class OutputFailureRenderer
9+
* Renderer for `PhpSchool\PhpWorkshop\Result\StdOutFailure`.
10+
*
1011
* @package PhpSchool\PhpWorkshop\ResultRenderer
1112
*/
1213
class OutputFailureRenderer implements ResultRendererInterface
@@ -18,14 +19,16 @@ class OutputFailureRenderer implements ResultRendererInterface
1819
private $result;
1920

2021
/**
21-
* @param StdOutFailure $result
22+
* @param StdOutFailure $result The failure.
2223
*/
2324
public function __construct(StdOutFailure $result)
2425
{
2526
$this->result = $result;
2627
}
2728

2829
/**
30+
* Print the actual and expected output.
31+
*
2932
* @param ResultsRenderer $renderer
3033
* @return string
3134
*/

src/ResultRenderer/ResultRendererInterface.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,25 @@
22

33
namespace PhpSchool\PhpWorkshop\ResultRenderer;
44

5-
use PhpSchool\PhpWorkshop\Result\ResultInterface;
6-
75
/**
8-
* Interface ResultRendererInterface
6+
* The interface, result renderers should adhere to.
7+
*
98
* @package PhpSchool\PhpWorkshop\ResultRenderer
9+
* @author Aydin Hassan <aydin@hotmail.co.uk>
1010
*/
1111
interface ResultRendererInterface
1212
{
1313

1414
/**
15-
* @param ResultsRenderer $renderer
16-
* @return string
15+
* This method should return a string representation of the result,
16+
* formatted for output on the command line.
17+
*
18+
* The `PhpSchool\PhpWorkshop\ResultRenderer\ResultsRenderer` method has
19+
* various helpers to render line breaks, colour output and can also render child
20+
* results.
21+
*
22+
* @param ResultsRenderer $renderer The main renderer instance.
23+
* @return string The string representation of the result.
1724
*/
1825
public function render(ResultsRenderer $renderer);
1926
}

src/ResultRenderer/ResultsRenderer.php

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
use PhpSchool\PhpWorkshop\UserState;
1616

1717
/**
18-
* Class ResultsRenderer
18+
* Renderer which renders a `\PhpSchool\PhpWorkshop\ResultAggregator` and writes it the output.
19+
*
1920
* @package PhpSchool\PhpWorkshop\ResultRenderer
2021
*/
2122
class ResultsRenderer
@@ -51,11 +52,11 @@ class ResultsRenderer
5152
private $resultRendererFactory;
5253

5354
/**
54-
* @param $appName
55-
* @param Color $color
56-
* @param TerminalInterface $terminal
57-
* @param ExerciseRepository $exerciseRepository
58-
* @param SyntaxHighlighter $syntaxHighlighter
55+
* @param string $appName The name of the binary to run this workshop.
56+
* @param Color $color A instance of `Color` used to colour strings with ANSI escape codes.
57+
* @param TerminalInterface $terminal A helper to get information regarding the current terminal.
58+
* @param ExerciseRepository $exerciseRepository The exercise repository.
59+
* @param SyntaxHighlighter $syntaxHighlighter A PHP syntax highlighter for the terminal, uses ANSI escape codes.
5960
*/
6061
public function __construct(
6162
$appName,
@@ -74,10 +75,13 @@ public function __construct(
7475
}
7576

7677
/**
77-
* @param ResultAggregator $results
78-
* @param ExerciseInterface $exercise
79-
* @param UserState $userState
80-
* @param OutputInterface $output
78+
* Render the result set to the output and statistics on the number of exercises completed and
79+
* remaining.
80+
*
81+
* @param ResultAggregator $results The result set.
82+
* @param ExerciseInterface $exercise The exercise instance that was just attempted.
83+
* @param UserState $userState The current state of the student's progress.
84+
* @param OutputInterface $output The output instance.
8185
*/
8286
public function render(
8387
ResultAggregator $results,
@@ -201,8 +205,11 @@ private function styleArray(array $lines, array $styles)
201205
}
202206

203207
/**
208+
* Style/colour a string.
209+
* Can be any of: black, red, green, yellow, blue, magenta, cyan, white, bold, italic, underline
210+
*
204211
* @param string $string
205-
* @param array|string $colourOrStyle
212+
* @param array|string $colourOrStyle A single style as a string or multiple styles as an array.
206213
*
207214
* @return string
208215
*
@@ -222,15 +229,19 @@ public function style($string, $colourOrStyle)
222229
}
223230

224231
/**
225-
* @param ResultInterface $result
226-
* @return string
232+
* Render a result. Attempt to find the correct renderer via the result renderer factory.
233+
*
234+
* @param ResultInterface $result The result.
235+
* @return string The string representation of the result.
227236
*/
228237
public function renderResult(ResultInterface $result)
229238
{
230239
return $this->resultRendererFactory->create($result)->render($this);
231240
}
232241

233242
/**
243+
* Draw a line break across the terminal.
244+
*
234245
* @return string
235246
*/
236247
public function lineBreak()

0 commit comments

Comments
 (0)