Skip to content

Commit d871ff8

Browse files
authored
Merge pull request #45 from php-school/problem-file-updates
Problem file updates for cloud compat
2 parents a888a76 + 0789d83 commit d871ff8

File tree

15 files changed

+197
-184
lines changed

15 files changed

+197
-184
lines changed

composer.lock

Lines changed: 127 additions & 128 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exercises/a-match-made-in-heaven/problem/problem.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
You have been given a piece of code (look for `a-match-made-in-heaven.php` in your working directory) which is full of bugs.
1+
You have been given a piece of code (look for `a-match-made-in-heaven.php` in {{context cli 'your working directory'}} {{context cloud 'the editor'}}) which is full of bugs.
22
The code has been implemented badly, using a `switch` statement. Your job is to fix the code, by using the newly introduced `match` expression in PHP 8.
33

44
The piece of code is supposed to take a string representing a keyboard keypress and convert it to its equivalent ANSI decimal code.
@@ -20,8 +20,7 @@ The key presses will be provided as strings via command line arguments. Only one
2020
----------------------------------------------------------------------
2121
## HINTS
2222

23-
Documentation on the `match` expression can be found by pointing your browser here:
24-
[https://www.php.net/manual/en/control-structures.match.php]()
23+
{{ doc match en control-structures.match.php }}
2524

2625
Remember the first argument will be a randomly picked supported keypress.
2726

exercises/a-safe-space-for-nulls/problem/problem.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ And finally, the most important part, all properties which may be `NULL` should
6363

6464
Remember your program will be passed no arguments. There will be a `User` object populated for you under the variable `$user`. It is available at the beginning of your script.
6565

66-
Documentation on the Null Safe Operator can be found by pointing your browser here:
67-
[https://www.php.net/manual/en/language.oop5.basic.php#language.oop5.basic.nullsafe]()
66+
{{ doc 'Null Safe Operator' en language.oop5.basic.php#language.oop5.basic.nullsafe }}
67+
6868

6969
----------------------------------------------------------------------
7070
## EXTRA

exercises/all-mixed-up/problem/problem.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,9 @@ We will call your function automatically with a bunch of different types to make
4040

4141
We will specifically check that you used the `mixed` type. Omitting the type will not pass.
4242

43-
Documentation on the `mixed` type can be found by pointing your browser here:
44-
[https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.mixed]()
43+
{{ doc 'mixed' en language.types.declarations.php#language.types.declarations.mixed }}
4544

46-
Documentation on `get_debug_type` can be found by pointing your browser here:
47-
[https://www.php.net/manual/en/function.get-debug-type.php]()
45+
{{ doc 'get_debug_type' en function.get-debug-type.php }}
4846

4947
----------------------------------------------------------------------
5048
## EXTRA

exercises/caution-with-catches/problem/problem.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ For this exercise this function will always throw an exception but unfortunately
1313

1414
To pass this exercise you will need to call the `verify_password` function with the password provided, handle the exception and output `"Given password is invalid, please try again"`.
1515

16-
PHP 8 allows you to handle the exception without capturing the exception itself which will ensure this message is not leaked further.
16+
PHP 8 allows you to handle the exception without capturing the exception itself in to a variable, which will ensure this message is not leaked further.
1717

1818
### The advantages of non capturing catches
1919

@@ -24,5 +24,5 @@ PHP 8 allows you to handle the exception without capturing the exception itself
2424
----------------------------------------------------------------------
2525
## HINTS
2626

27-
Documentation on the non-capturing catches feature is sparse without examples, so the RFC has the most amount of detail:
28-
[https://wiki.php.net/rfc/non-capturing_catches]()
27+
Documentation on the non-capturing catches feature is sparse and without examples, so the RFC has the most amount of detail:
28+
[https://wiki.php.net/rfc/non-capturing_catches](https://wiki.php.net/rfc/non-capturing_catches)

exercises/have-the-last-say/problem/problem.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ htmlspecialchars($string, ENT_COMPAT | ENT_HTML, 'UTF-8', false);
2727

2828
We only want to change the last argument (double_encode) of the function to false (the default is true). However, we are forced to specify all the other arguments, even though they have not changed from the defaults.
2929

30-
Named arguments allows to write the same, but in a more succinct fashion:
30+
Named arguments allows us to write the same, but in a more succinct fashion:
3131

3232
```php
3333
htmlspecialchars($string, double_encode: false);
@@ -51,14 +51,11 @@ You will most likely need a loop to process all the data in the file.
5151

5252
You will need to keep reading from the file until it has been fully read. `feof` is your friend here and will inform you whether there is any data left to read.
5353

54-
Documentation on the `fopen` function can be found by pointing your browser here:
55-
[https://www.php.net/manual/en/function.fopen.php]()
54+
{{ doc 'fopen' en function.fopen.php }}
5655

57-
Documentation on the `fgetcsv` function can be found by pointing your browser here:
58-
[https://www.php.net/manual/en/function.fgetcsv.php]()
56+
{{ doc 'fgetcsv' en function.fgetcsv.php }}
5957

60-
Documentation on the `feof` function can be found by pointing your browser here:
61-
[https://www.php.net/manual/en/function.feof.php]()
58+
{{ doc 'feof' en function.feof.php }}
6259

6360
----------------------------------------------------------------------
6461
## EXTRA

exercises/infinite-divisions/problem/problem.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ Based on those values you should print a specific message followed by a new line
2424
----------------------------------------------------------------------
2525
## HINTS
2626

27-
Documentation on the fdiv function can be found by pointing your browser here:
28-
[https://www.php.net/manual/en/function.fdiv.php]()
27+
{{ doc 'fdiv' en function.fdiv.php }}
28+
2929

exercises/lord-of-the-strings/problem/problem.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,23 @@ The result column should be `true` or `false` based on the result of the corresp
4444
----------------------------------------------------------------------
4545
## HINTS
4646

47+
{{ cli }}
4748
Point your browser to [https://getcomposer.org/doc/00-intro.md](https://getcomposer.org/doc/00-intro.md) which will walk you through **Installing Composer** if you haven't already!
4849

4950
Use `composer init` to create your `composer.json` file with interactive search.
51+
{{ cli }}
52+
53+
{{ cloud }}
54+
Composer is installed and ready to go on cloud, use the `Composer Deps` button in the editor to search for and install your dependencies. While you should read the documentation for [Composer](https://getcomposer.org/doc/00-intro.md), it's important to note that the way we manage dependencies on PHP School cloud, is not how you would manage them in your own projects. We abstract away the `composer.json` file to keep it simple.
55+
{{ cloud }}
5056

5157
For more details look at the docs for...
5258

53-
**Composer** - [https://getcomposer.org/doc/01-basic-usage.md](https://getcomposer.org/doc/01-basic-usage.md)
54-
**Symfony Console** - [https://symfony.com/doc/current/components/console.html](https://symfony.com/doc/current/components/console.html)
55-
**str_contains** - [https://www.php.net/manual/en/function.str-contains.php](https://www.php.net/manual/en/function.str-contains.php)
56-
**str_starts_with** - [https://www.php.net/manual/en/function.str-starts-with.php](https://www.php.net/manual/en/function.str-starts-with.php)
57-
**str_ends_with** - [https://www.php.net/manual/en/function.str-ends-with.php](https://www.php.net/manual/en/function.str-ends-with.php)
59+
* **Composer** - [https://getcomposer.org/doc/01-basic-usage.md](https://getcomposer.org/doc/01-basic-usage.md)
60+
* **Symfony Console** - [https://symfony.com/doc/current/components/console.html](https://symfony.com/doc/current/components/console.html)
61+
* **str_contains** - [https://www.php.net/manual/en/function.str-contains.php](https://www.php.net/manual/en/function.str-contains.php)
62+
* **str_starts_with** - [https://www.php.net/manual/en/function.str-starts-with.php](https://www.php.net/manual/en/function.str-starts-with.php)
63+
* **str_ends_with** - [https://www.php.net/manual/en/function.str-ends-with.php](https://www.php.net/manual/en/function.str-ends-with.php)
5864

5965
For Symfony Console you will want to look specifically for the Table Helper.
6066

exercises/php-gets-a-promotion/problem/problem.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
You have been given a piece of code (look for `php-gets-a-promotion.php` in your working directory) which provides a class written for PHP 7.
1+
You have been given a piece of code (look for `php-gets-a-promotion.php` in {{context cli 'your working directory'}} {{context cloud 'the editor'}}) which provides a class written for PHP 7.
22

33
The code itself works well, assigning constructor arguments to the class properties.
44

@@ -18,12 +18,11 @@ Focus on converting the constructor to a terse format using constructor property
1818
----------------------------------------------------------------------
1919
## HINTS
2020

21-
Documentation on the constructor property promotion feature can be found by pointing your browser here:
22-
[https://www.php.net/manual/en/language.oop5.decon.php#language.oop5.decon.constructor.promotion]()
21+
{{ doc 'Constructor Property Promotion' en language.oop5.decon.php#language.oop5.decon.constructor.promotion }}
2322

24-
Remember to keep the same visibility for the properties
23+
Remember to keep the same visibility for the properties.
2524

26-
You will be expected to make use of the constructor property promotion feature
25+
You will be expected to make use of the constructor property promotion feature.
2726

28-
You should have less code than the provided initial code
27+
You should have less code than the provided initial code.
2928

exercises/stringify-to-demystify/problem/problem.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
`__toString()` is a magic class method long-standing in PHP but never truly something you could rely on unless you rolled your own interface. All that has changed with the simple introduction of the `Stringable` interface in PHP 8.
22

3-
`Stringable` is a simple interface that requires the implementation of `__toString(): string`
3+
`Stringable` is a simple interface that requires the implementation of the method `__toString(): string`
44

55
----------------------------------------------------------------------
66

@@ -35,13 +35,11 @@ Your program may also receive successful payloads, which you should ignore for t
3535

3636
To easily read the request body you can use `file_get_contents('php://input')`
3737

38-
For more details look at the docs for...
38+
{{ doc 'Stringable' en class.stringable.php }}
3939

40-
**Stringable** - [https://www.php.net/manual/en/class.stringable.php]()
41-
42-
Note that while the `Stringable` interface isn't required to pass the type hint check, however, it should be used if not only to show intent.
40+
Note that while the `Stringable` interface isn't required to pass the type hint check (simply implementing the method `__toString` is enough), it should be used if not only to signal intent.
4341

4442
Oh, and don't forget about the basics for classes and interfaces :)
4543

46-
**class** - [https://www.php.net/manual/en/language.oop5.basic.php]()
47-
**interfaces** - [https://www.php.net/manual/en/language.oop5.interfaces.php]()
44+
* **class** - [https://www.php.net/manual/en/language.oop5.basic.php](https://www.php.net/manual/en/language.oop5.basic.php)
45+
* **interfaces** - [https://www.php.net/manual/en/language.oop5.interfaces.php](https://www.php.net/manual/en/language.oop5.interfaces.php)

exercises/the-attributes-of-success/problem/problem.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
You have been given a few pieces of code (look for `attributes.php`, `deserialize.php` & `the-attributes-of-success.php` in your working directory).
1+
You have been given a few pieces of code (look for `attributes.php`, `deserialize.php` & `the-attributes-of-success.php` in {{context cli 'your working directory'}} {{context cloud 'the editor'}}).
22

33
Your entry point is `the-attributes-of-success.php`. This is the file you should edit and work on. The other files should not be modified. However, they are included by `the-attributes-of-success.php`.
44

5+
{{ cli }}
56
You can run and verify your program like so:
67

78
```sh
89
$ {appname} run the-attributes-of-success.php
910
$ {appname} verify the-attributes-of-success.php
1011
```
12+
{{ cli }}
1113

12-
Your task is split into two sections. The overall task is to write a class using properties and attributes which describe how to map data to an instance of the class.
14+
Your task is split in to two sections. The overall task is to write a class using properties and attributes which describe how to map data to an instance of the class.
1315

1416
The data will be passed to you in a JSON encoded string via the first command line argument.
1517

@@ -68,13 +70,19 @@ Use the `Skip` attribute on the `id` property of our `Review` class to tell our
6870

6971
By now you should be able to call the `deserialize` function with the `JSON` data and your class name.
7072

73+
{{ cli }}
7174
When executing your program with
7275

7376
```sh
7477
$ {appname} run the-attributes-of-success.php
7578
```
7679

7780
You should see a dump of your `Review` instance.
81+
{{ cli }}
82+
83+
{{ cloud }}
84+
When you execute your program by pressing `Run` you should see a dump of your `Review` instance.
85+
{{ cloud }}
7886

7987
Here comes our problem: The reviewers name is not anonymous. We have to comply with strict privacy laws, we cannot display this data without the reviewer's permission.
8088

@@ -126,19 +134,18 @@ The last task is to dump your object instance out using the PHP function `var_du
126134
----------------------------------------------------------------------
127135
## HINTS
128136

129-
Documentation on the Attributes feature can be found by pointing your browser here:
130-
[https://www.php.net/manual/en/language.attributes.overview.php]()
137+
{{ doc 'Attributes' en language.attributes.overview.php }}
131138

132139
Remember, do not edit `attributes.php` or `deserialize.php` - verification will fail if you do. Feel free to read the files to get a better understanding of the deserialization process.
133140

134141
You must call the `deserialize` function and you must use the `var_dump` function to output your deserialized object.
135142

136143
If you want to see the `JSON` data - use `var_dump` to dump it out.
137144

138-
For verification purposes, the order the properties defined in your `Review` class is important. Define them in the same order they are described to you.
145+
For verification purposes, the order the properties are defined in your `Review` class is important. Define them in the same order they are described to you.
139146

140147
## Extra
141148

142-
If you're not sure how to access command line arguments - you should maybe try a different workshop which covers that topic. Try `learnyouphp`.
149+
If you're not sure how to access command line arguments - you should maybe try a different workshop which covers that topic. Try the Learn you PHP workshop.
143150

144151
`json_decode` can fail if it is passed a malformed string. Wrap the decode in a `try\catch` statement and pass the `JSON_THROW_ON_ERROR` flag to `json_decode`'s fourth parameter.

exercises/the-return-of-static/problem/problem.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
You have been given a piece of code (look for `the-return-of-static.php` in your working directory) which is using static return types.
1+
You have been given a piece of code (look for `the-return-of-static.php` in {{context cli 'your working directory'}} {{context cloud 'the editor'}}) which is using static return types.
22

33
You will find two classes. `File`, a base class, and `Image` a class extending and adding behavior to `File`. We instantiate `Image`, set some properties using a fluent interface and then dump the object using `var_dump`.
44

5+
{{ cli }}
56
If you run the code using `{appname} run the-return-of-static.php` you will see it is broken.
7+
{{ cli }}
8+
9+
{{ cloud }}
10+
If you run the code by clicking the `Run` button in the editor you will see it is broken.
11+
{{ cloud }}
612

713
Locate and fix the issue!
814

@@ -14,8 +20,8 @@ Locate and fix the issue!
1420
----------------------------------------------------------------------
1521
## HINTS
1622

17-
(Brief) Documentation on the static return type feature can be found by pointing your browser here:
18-
[https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.static]()
23+
(Brief) documentation on the static return type feature can be found by pointing your browser here:
24+
[https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.static](https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.static)
1925

2026
The static return type enforces methods to return an instance of the class that the method was called from, rather than the one it was defined in.
2127

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
You have been given a piece of code (look for `throw-an-expression.php` in your working directory) which is checking the requested URL and throwing an exception when a secret area of the website is accessed.
1+
You have been given a piece of code (look for `throw-an-expression.php` in {{context cli 'your working directory'}} {{context cloud 'the editor'}}) which is checking the requested URL and throwing an exception when a secret area of the website is accessed.
22

33
If the request is allowed, `Welcome!` is printed out.
44

55

66
Traditionally, pre PHP 8, an exception throw has been a statement. There are certain places where statements cannot be used, and only expressions can be used. For example, in ternaries and short closures, only expressions can be used.
77

8-
Now with PHP 8, throw statements are expressions making them available to use in pretty much all locations.
8+
Now with PHP 8, throw statements are expressions, making them available to use in pretty much all locations.
99

1010
----------------------------------------------------------------------
1111
Your task is to convert the `if` statement to one line of code, using the ternary operator.
1212

13-
### The advantages of throwing being an exception
13+
### The advantages of throw being an exception
1414

1515
* It is possible to throw an exception in a short closure
1616
* It is possible to throw an exception in a ternary or coalesce operation
1717

1818
----------------------------------------------------------------------
1919
## HINTS
2020

21-
Documentation on throwing exception can be found by pointing your browser here:
22-
[https://www.php.net/manual/en/language.exceptions.php]()
21+
{{ doc 'throwing exceptions' en language.exceptions.php }}
2322

exercises/unite-the-types/problem/problem.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ The function you implement must be called `adder`.
3030

3131
It is up to you to pass the numbers to your function.
3232

33-
Documentation on union types can be found by pointing your browser here:
34-
[https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.union]()
33+
{{ doc 'union types' en language.types.declarations.php#language.types.declarations.union }}
3534

3635
----------------------------------------------------------------------
3736
## EXTRA

test/Exercise/LordOfTheStringsTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PhpSchool\PHP8Appreciate\Exercise\LordOfTheStrings;
66
use PhpSchool\PhpWorkshop\Application;
7+
use PhpSchool\PhpWorkshop\Result\ComposerFailure;
78
use PhpSchool\PhpWorkshop\Result\Failure;
89
use PhpSchool\PhpWorkshop\Result\FunctionRequirementsFailure;
910
use PhpSchool\PhpWorkshop\TestUtils\WorkshopExerciseTest;
@@ -25,7 +26,12 @@ public function testWithNoComposerFile(): void
2526
$this->runExercise('solution-no-code.php');
2627

2728
$this->assertVerifyWasNotSuccessful();
28-
$this->assertResultsHasFailure(Failure::class, 'No composer.json file found');
29+
$this->assertResultsHasFailureAndMatches(ComposerFailure::class, function (ComposerFailure $composerFailure) {
30+
self::assertTrue($composerFailure->isMissingComponent());
31+
self::assertEquals('composer.json', $composerFailure->getMissingComponent());
32+
33+
return true;
34+
});
2935
}
3036

3137
public function testWithNoCode(): void

0 commit comments

Comments
 (0)