Skip to content

Commit

Permalink
Merge b601d50 into ae95880
Browse files Browse the repository at this point in the history
  • Loading branch information
lsolesen committed Oct 8, 2021
2 parents ae95880 + b601d50 commit da689dd
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/Client.php
Expand Up @@ -86,11 +86,6 @@ public function createNewRegistrations(array $registrations)
$value = substr($value, 0, 30);
}
}
foreach (array('.TidlSkole') as $variable) {
if (strpos($key, $variable) !== false) {
$value = substr($value, 0, 48);
}
}
foreach (array('.CprNr') as $variable) {
if (strpos($key, $variable) !== false) {
$value = substr($value, 0, 20);
Expand All @@ -107,6 +102,17 @@ public function createNewRegistrations(array $registrations)
if (strpos($key, '.Kommune') !== false) {
$value = $this->getUtilityClass()->getMunicipalityCode($value);
}
foreach (array('.TidlSkole') as $variable) {
if (strpos($key, $variable) !== false) {
$value = substr($value, 0, 48);
}
}
foreach (array('.Klasse') as $variable) {
if (strpos($key, $variable) !== false) {
$value = substr($value, 0, 2);
$value = $this->getUtilityClass()->fixClass($value);
}
}
$reg->addChild($key, htmlspecialchars($value));
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/Utility.php
Expand Up @@ -36,6 +36,9 @@ class Utility implements UtilityInterface
public function getCountryCode($country)
{
$rows = $this->getCSV(DIRNAME(__FILE__) . "/data/Landekoder.csv", $country);
if ($rows == 0) {
return 0;
}
$stored_in_column = 1;
return $rows[$stored_in_column];
}
Expand All @@ -50,6 +53,9 @@ public function getCountryCode($country)
public function getMunicipalityCode($municipality)
{
$rows = $this->getCSV(DIRNAME(__FILE__) . "/data/Kommuner.csv", $municipality);
if ($rows == 0) {
return 0;
}
$stored_in_column = 2;
return $rows[$stored_in_column];
}
Expand All @@ -67,6 +73,17 @@ public function fixPhoneNumber($phonenumber)
return $string;
}

/**
* Make sure that 'klasse' only returns number
*
* $param string $class Klasse string
*
* $return integer
*/
public function fixClass($class)
{
return preg_replace('/[^0-9]/', '', $class);
}

/**
* Loops through csv file and stops with search
Expand Down
1 change: 1 addition & 0 deletions tests/RegistrationRepositoryTest.php
Expand Up @@ -247,6 +247,7 @@ public function testEducationLongCourses()
'Elev.Adresse' => 'Ørnebjergvej 28',
'Elev.Lokalby' => 'Grejs',
'Elev.Kommune' => 'Vejle',
'Elev.Klasse' => '9.',
'Elev.Postnr' => '7100',
'Elev.Bynavn' => 'Vejle',
'Elev.CprNr' => '0101421942',
Expand Down
10 changes: 10 additions & 0 deletions tests/UtilityTest.php
Expand Up @@ -44,4 +44,14 @@ public function testGetMunicipalityCodeThatIsNotFound()
$utility = new Utility();
$this->assertEquals(0, $utility->getMunicipalityCode("NotFound"));
}

/**
* Test FixClass()
*/
public function testFixClassReturnsNumericValue()
{
$utility = new Utility();
$this->assertEquals(9, $utility->fixClass("9."));
$this->assertTrue(is_numeric($utility->fixClass("9.")));
}
}

0 comments on commit da689dd

Please sign in to comment.