Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync phone-number #803

Merged
merged 4 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions exercises/practice/phone-number/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@

Clean up user-entered phone numbers so that they can be sent SMS messages.

The **North American Numbering Plan (NANP)** is a telephone numbering system used by many countries in North America like the United States, Canada or Bermuda. All NANP-countries share the same international country code: `1`.
The **North American Numbering Plan (NANP)** is a telephone numbering system used by many countries in North America like the United States, Canada or Bermuda.
All NANP-countries share the same international country code: `1`.

NANP numbers are ten-digit numbers consisting of a three-digit Numbering Plan Area code, commonly known as *area code*, followed by a seven-digit local number. The first three digits of the local number represent the *exchange code*, followed by the unique four-digit number which is the *subscriber number*.
NANP numbers are ten-digit numbers consisting of a three-digit Numbering Plan Area code, commonly known as _area code_, followed by a seven-digit local number.
The first three digits of the local number represent the _exchange code_, followed by the unique four-digit number which is the _subscriber number_.

The format is usually represented as

```text
(NXX)-NXX-XXXX
NXX NXX-XXXX
```

where `N` is any digit from 2 through 9 and `X` is any digit from 0 through 9.

Your task is to clean up differently formatted telephone numbers by removing punctuation and the country code (1) if present.
Sometimes they also have the country code (represented as `1` or `+1`) prefixed.

Your task is to clean up differently formatted telephone numbers by removing punctuation and the country code if present.

For example, the inputs

- `+1 (613)-995-0253`
- `613-995-0253`
- `1 613 995 0253`
Expand Down
4 changes: 2 additions & 2 deletions exercises/practice/phone-number/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
]
},
"blurb": "Clean up user-entered phone numbers so that they can be sent SMS messages.",
"source": "Event Manager by JumpstartLab",
"source_url": "https://tutorials.jumpstartlab.com/projects/eventmanager.html"
"source": "Exercise by the JumpstartLab team for students at The Turing School of Software and Design.",
"source_url": "https://turing.edu"
}
22 changes: 0 additions & 22 deletions exercises/practice/phone-number/.meta/example.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
<?php

/*
* By adding type hints and enabling strict type checking, code can become
* easier to read, self-documenting and reduce the number of potential bugs.
* By default, type declarations are non-strict, which means they will attempt
* to change the original type to match the type specified by the
* type-declaration.
*
* In other words, if you pass a string to a function requiring a float,
* it will attempt to convert the string value to a float.
*
* To enable strict mode, a single declare directive must be placed at the top
* of the file.
* This means that the strictness of typing is configured on a per-file basis.
* This directive not only affects the type declarations of parameters, but also
* a function's return type.
*
* For more info review the Concept on strict type checking in the PHP track
* <link>.
*
* To disable strict typing, comment out the directive below.
*/

declare(strict_types=1);

class PhoneNumber
Expand Down
33 changes: 30 additions & 3 deletions exercises/practice/phone-number/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# This is an auto-generated file. Regular comments will be removed when this
# file is regenerated. Regenerating will not touch any manually added keys,
# so comments can be added in a "comment" key.
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[79666dce-e0f1-46de-95a1-563802913c35]
description = "cleans the number"
Expand All @@ -13,6 +20,11 @@ description = "cleans numbers with multiple spaces"

[598d8432-0659-4019-a78b-1c6a73691d21]
description = "invalid when 9 digits"
include = false

[2de74156-f646-42b5-8638-0ef1d8b58bc2]
description = "invalid when 9 digits"
reimplements = "598d8432-0659-4019-a78b-1c6a73691d21"

[57061c72-07b5-431f-9766-d97da7c4399d]
description = "invalid when 11 digits does not start with a 1"
Expand All @@ -25,12 +37,27 @@ description = "valid when 11 digits and starting with 1 even with punctuation"

[c6a5f007-895a-4fc5-90bc-a7e70f9b5cad]
description = "invalid when more than 11 digits"
include = false

[4a1509b7-8953-4eec-981b-c483358ff531]
description = "invalid when more than 11 digits"
reimplements = "c6a5f007-895a-4fc5-90bc-a7e70f9b5cad"

[63f38f37-53f6-4a5f-bd86-e9b404f10a60]
description = "invalid with letters"
include = false

[eb8a1fc0-64e5-46d3-b0c6-33184208e28a]
description = "invalid with letters"
reimplements = "63f38f37-53f6-4a5f-bd86-e9b404f10a60"

[4bd97d90-52fd-45d3-b0db-06ab95b1244e]
description = "invalid with punctuations"
include = false

[065f6363-8394-4759-b080-e6c8c351dd1f]
description = "invalid with punctuations"
reimplements = "4bd97d90-52fd-45d3-b0db-06ab95b1244e"

[d77d07f8-873c-4b17-8978-5f66139bf7d7]
description = "invalid if area code starts with 0"
Expand Down
100 changes: 74 additions & 26 deletions exercises/practice/phone-number/PhoneNumberTest.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
<?php

/*
* By adding type hints and enabling strict type checking, code can become
* easier to read, self-documenting and reduce the number of potential bugs.
* By default, type declarations are non-strict, which means they will attempt
* to change the original type to match the type specified by the
* type-declaration.
*
* In other words, if you pass a string to a function requiring a float,
* it will attempt to convert the string value to a float.
*
* To enable strict mode, a single declare directive must be placed at the top
* of the file.
* This means that the strictness of typing is configured on a per-file basis.
* This directive not only affects the type declarations of parameters, but also
* a function's return type.
*
* For more info review the Concept on strict type checking in the PHP track
* <link>.
*
* To disable strict typing, comment out the directive below.
*/

declare(strict_types=1);

class PhoneNumberTest extends PHPUnit\Framework\TestCase
Expand All @@ -31,32 +9,51 @@ public static function setUpBeforeClass(): void
require_once 'PhoneNumber.php';
}

/**
* uuid 79666dce-e0f1-46de-95a1-563802913c35
* @testdox cleans the number
*/
public function testCleansTheNumber(): void
{
$number = new PhoneNumber('(223) 456-7890');
$this->assertEquals('2234567890', $number->number());
}

/**
* uuid c360451f-549f-43e4-8aba-fdf6cb0bf83f
* @testdox cleans numbers with dots
*/
public function testCleansTheNumberWithDots(): void
{
$number = new PhoneNumber('223.456.7890');
$this->assertEquals('2234567890', $number->number());
}

/**
* uuid 08f94c34-9a37-46a2-a123-2a8e9727395d
* @testdox cleans numbers with multiple spaces
*/
public function testCleansTheNumberWithMultipleSpaces(): void
{
$number = new PhoneNumber('223 456 7890 ');
$this->assertEquals('2234567890', $number->number());
}

/**
* uuid 2de74156-f646-42b5-8638-0ef1d8b58bc2
* @testdox invalid when 9 digits
*/
public function testInvalidWhen9Digits(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('incorrect number of digits');

new PhoneNumber('123456789');
}

/**
* uuid 57061c72-07b5-431f-9766-d97da7c4399d
* @testdox invalid when 11 digits does not start with a 1
*/
public function testInvalidWhen11DigitsDoesNotStartWithA1(): void
{
$this->expectException(InvalidArgumentException::class);
Expand All @@ -65,42 +62,65 @@ public function testInvalidWhen11DigitsDoesNotStartWithA1(): void
new PhoneNumber('22234567890');
}

/**
* uuid 9962cbf3-97bb-4118-ba9b-38ff49c64430
* @testdox valid when 11 digits and starting with 1
*/
public function testValidWhen11DigitsAndStartingWith1(): void
{
$number = new PhoneNumber('12234567890');
$this->assertEquals('2234567890', $number->number());
}

/**
* uuid fa724fbf-054c-4d91-95da-f65ab5b6dbca
* @testdox valid when 11 digits and starting with 1 even with punctuation
*/
public function testValidWhen11DigitsAndStartingWith1EvenWithPunctuation(): void
{
$number = new PhoneNumber('+1 (223) 456-7890');
$this->assertEquals('2234567890', $number->number());
}

/**
* uuid 4a1509b7-8953-4eec-981b-c483358ff531
* @testdox invalid when more than 11 digits
*/
public function testInvalidWhenMoreThan11Digits(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('more than 11 digits');

new PhoneNumber('321234567890');
}

/**
* uuid eb8a1fc0-64e5-46d3-b0c6-33184208e28a
* @testdox invalid with letters
*/
public function testInvalidWithLetters(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('letters not permitted');

new PhoneNumber('123-abc-7890');
new PhoneNumber('523-abc-7890');
}

/**
* uuid 065f6363-8394-4759-b080-e6c8c351dd1f
* @testdox invalid with punctuations
*/
public function testInvalidWithPunctuation(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('punctuations not permitted');

new PhoneNumber('123-@:!-7890');
new PhoneNumber('523-@:!-7890');
}

/**
* uuid d77d07f8-873c-4b17-8978-5f66139bf7d7
* @testdox invalid if area code starts with 0
*/
public function testInvalidIfAreaCodeStartsWith0(): void
{
$this->expectException(InvalidArgumentException::class);
Expand All @@ -109,6 +129,10 @@ public function testInvalidIfAreaCodeStartsWith0(): void
new PhoneNumber('(023) 456-7890');
}

/**
* uuid c7485cfb-1e7b-4081-8e96-8cdb3b77f15e
* @testdox invalid if area code starts with 1
*/
public function testInvalidIfAreaCodeStartsWith1(): void
{
$this->expectException(InvalidArgumentException::class);
Expand All @@ -117,6 +141,10 @@ public function testInvalidIfAreaCodeStartsWith1(): void
new PhoneNumber('(123) 456-7890');
}

/**
* uuid 4d622293-6976-413d-b8bf-dd8a94d4e2ac
* @testdox invalid if exchange code starts with 0
*/
public function testInvalidIfExchangeCodeStartsWith0(): void
{
$this->expectException(InvalidArgumentException::class);
Expand All @@ -125,6 +153,10 @@ public function testInvalidIfExchangeCodeStartsWith0(): void
new PhoneNumber('(223) 056-7890');
}

/**
* uuid 4cef57b4-7d8e-43aa-8328-1e1b89001262
* @testdox invalid if exchange code starts with 1
*/
public function testInvalidIfExchangeCodeStartsWith1(): void
{
$this->expectException(InvalidArgumentException::class);
Expand All @@ -133,6 +165,10 @@ public function testInvalidIfExchangeCodeStartsWith1(): void
new PhoneNumber('(223) 156-7890');
}

/**
* uuid 9925b09c-1a0d-4960-a197-5d163cbe308c
* @testdox invalid if area code starts with 0 on valid 11-digit number
*/
public function testInvalidIfAreaCodeStartsWith0OnValid11DigitNumber(): void
{
$this->expectException(InvalidArgumentException::class);
Expand All @@ -141,6 +177,10 @@ public function testInvalidIfAreaCodeStartsWith0OnValid11DigitNumber(): void
new PhoneNumber('1 (023) 456-7890');
}

/**
* uuid 3f809d37-40f3-44b5-ad90-535838b1a816
* @testdox invalid if area code starts with 1 on valid 11-digit number
*/
public function testInvalidIfAreaCodeStartsWith1OnValid11DigitNumber(): void
{
$this->expectException(InvalidArgumentException::class);
Expand All @@ -149,6 +189,10 @@ public function testInvalidIfAreaCodeStartsWith1OnValid11DigitNumber(): void
new PhoneNumber('1 (123) 456-7890');
}

/**
* uuid e08e5532-d621-40d4-b0cc-96c159276b65
* @testdox invalid if exchange code starts with 0 on valid 11-digit number
*/
public function testInvalidIfExchangeCodeStartsWith0OnValid11DigitNumber(): void
{
$this->expectException(InvalidArgumentException::class);
Expand All @@ -157,6 +201,10 @@ public function testInvalidIfExchangeCodeStartsWith0OnValid11DigitNumber(): void
new PhoneNumber('1 (223) 056-7890');
}

/**
* uuid 57b32f3d-696a-455c-8bf1-137b6d171cdf
* @testdox invalid if exchange code starts with 1 on valid 11-digit number
*/
public function testInvalidIfExchangeCodeStartsWith1OnValid11DigitNumber(): void
{
$this->expectException(InvalidArgumentException::class);
Expand Down