Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
63 changes: 63 additions & 0 deletions src/AgeCalculator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

<?php

/**
* @author Renato Martins
* Date: 09/09/2017
* Time: 21:00
*/
class AgeCalculator
{

/**
* Funcao usada para calcular
* a idade com base no ano de nascimento
* @param $yearBirth
* @return false|string
*/
function getAge($yearBirth)
{


/*
* Verificar que o parametro de entrada foi providenciado não é igual a null
*/
if (!$yearBirth) {

trigger_error("Parametro de entrada \"Ano de nascimento \" nao foi inserido ", E_USER_ERROR);
return null;
}
//verificar que o parametro de entrada é numerico.
else if (!is_numeric($yearBirth)) {
trigger_error("Parametro de entrada não é numérico", E_USER_ERROR);
return null;
}
//verificar que o parametro de entrada tem 4 caracteres.
else if(strlen($yearBirth)!=4){
trigger_error("Parametro de entrada deve ter 4 digitos",E_USER_ERROR);
return null;
}
else{

/*
* O format ("o") permite que a data retorne somente o ano da data actual.
* http://php.net/manual/en/function.date.php
*/
$thisYear = date("o");

$esteAno=3;
// a subtracao do ano de nascimento
$toReturn = $thisYear - $yearBirth;

return $toReturn;

}





}


}
67 changes: 67 additions & 0 deletions src/GitHubAngola.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

/**
* User: Renato Martins
* Date: 12/09/2017
* Time: 21:13
*/
class GitHubAngola
{


/**
* Função usada para ler o endpoint do gitHub
* e obter todos utilizadores em Angola
* =====AUTENTICACAO EM FALTA====
* @return array
*/
function getGitHubAngolanUsers()
{

$toReturn = array();
$github_url = 'https://api.github.com/search/users?q=location:Luanda/Angola';
$github_json = file_get_contents($github_url);
$github_array = json_decode($github_json, true);


if (!empty($github_array)) {

foreach ($github_array['data'] as $names) {

array_push($toReturn, ['total_count']['incomplete_results']['items']['login']);
}

}

return $toReturn;
}


/**
* Função usada para ler o endpoint do rest api do github
* e devolver a lista de utilizadores na localizcao solicitada.
* ==== AUTENTICACAO EM FALTA ====
* @param $location
* @return array
*/
function getGitHubUserByLocation($location)
{

$toReturn = array();
$github_url = 'https://api.github.com/search/users?q=location:' . $location;
$github_json = file_get_contents($github_url);
$github_array = json_decode($github_json, true);

if (!empty($github_array)) {

foreach ($github_array['data'] as $names) {

array_push($toReturn, ['total_count']['incomplete_results']['items']['login']);
}

}

return $toReturn;
}

}
61 changes: 61 additions & 0 deletions src/MinhaCalculadora.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

/**
* @author Renato Martins
* Date: 09/09/2017
* Time: 21:00
*/
class MinhaCalculadora
{

/**
* Funcao usada para calcular
* a idade com base no ano de nascimento
* @param $yearBirth
* @return false|string
*/
function getAge($yearBirth)
{


/*
* Verificar que o parametro de entrada foi providenciado não é igual a null
*/
if (!$yearBirth) {

trigger_error("Parametro de entrada \"Ano de nascimento \" nao foi inserido ", E_USER_ERROR);
return null;
}
//verificar que o parametro de entrada é numerico.
else if (!is_numeric($yearBirth)) {
trigger_error("Parametro de entrada não é numérico", E_USER_ERROR);
return null;
}
//verificar que o parametro de entrada tem 4 caracteres.
else if(strlen($yearBirth)!=4){
trigger_error("Parametro de entrada deve ter 4 digitos",E_USER_ERROR);
return null;
}
else{

/*
* O format ("o") permite que a data retorne somente o ano da data actual.
* http://php.net/manual/en/function.date.php
*/
$thisYear = date("o");

// a subtracao do ano de nascimento
$toReturn = $thisYear - $yearBirth;

return $toReturn;

}





}


}
86 changes: 86 additions & 0 deletions tests/testAgeCalculator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php
require('AgeCalculator.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Coding Dojo Angola</title>

<style type="text/css">

* {
padding: 0;
margin: 0;
}

#header {

width: 100%;
margin: 0;
height: 50px;
padding: 5px 10px;
font-family: 'Palatino Linotype';
background-color: #000;
color: #fff;
}

#content {

margin: 0 auto;
width: 960px;
padding: 5px;
font-family: "Trebuchet MS";

}

form p {

margin-bottom: 10px;
}


</style>

</head>
<body>

<div id="header">

<h1>Coding Dojo Angola</h1>
</div>

<div id="content">

<h1>Calculo da idade</h1>

<form action="index.php" method="post">

<p>Insira o seu <b>ano de nascimento</b><input name="inputAge" type="number"/></p>

<p>
<input type="submit" name="submit" value="Submit"/>
</p>
</form>


<?php
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Referente ao teste, a classe não deve contar html. O html pode estar por exemplo numa página /app/github/index.php. Porque nessa classe dentro de tests deve ser feito o teste usando PHPUnit

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guimar86 falta ajustes para o teste passar no StyleCI.
Dá uma olhada na analise do StyleCI para entender onde ajustar..

$calculator;

if (isset($_POST['submit'])) {


$userAge = $_POST['inputAge'];

$calculator = new AgeCalculator;
//new comment
echo("Voce tem " . $calculator->getAge($userAge) . " ano(s) de idade");

}


?>
</div>

</body>
</html>