HiveBrain v1.2.0
Get Started
← Back to all entries
patternphpModerate

I have a home test for job interview

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
interviewtestforhomejobhave

Problem

Nothing too special here, just a bunch of stuff. Please tell me if you would've done something different.

```
query($query) as $row){
$result[] = $row;
}
if (!empty($result)){
return $result;
}
return false;
}
}
/**
* This is the description for the class below.
*
* @package User
* @author Itai Sagi
* @version 1.0
* Basic User class
*
*/
class User{

// class constructor which accepts a user_id as an optional parameter,
// so you won't have to use the setUser() method.
function __construct($user_id = null){
$this -> userID = $user_id;
}

/**
* function setUser($id);
* This function sets the user_id for the class
* Parameters: int $user_id, assuming a valid $user_id;
* return values: the class itself.
**/
function setUser($user_id){
$this -> userID = $user_id;
return $this;
}
}

/**
* @package User
* @subpackage Contacts
* @author Itai Sagi
* @version 1.0
* The following class handles Contacts of a user.
* Usage example:
* searching user's contacts:
* $contacts = new Contacts();
* $foundContacts = $contacts -> setUser(76) -> searchContactsByName('John');
*
* getting contacts whose birthdays are up to 3 days from now:
* please note that here, the user is still set to '76'.
* $upcomingBirthdays = $contacts -> upcomingBirthdays(3);
*
**/

class Contacts extends User{

function __construct($user_id = null){
parent::__construct($user_id);
}

/**
* function: searchContactsByName($string);
* This function searches the user's contacts for users whose name contain $string;
* parameters: String $string - the name to search for
* re

Solution

To be honest, if I were an employer I wouldn't read past the first class, which contains static, global and use of the deprecated mysql_. They should be avoided, especially mysql_ which should be replaced by mysqli or PDO.

All of your classes are tightly coupled to SQL_Helper due to the static functions. If you passed in the SQL_Helper into each class (dependency injection) in the constructor, you could remove this tight coupling.

Context

StackExchange Code Review Q#10015, answer score: 11

Revisions (0)

No revisions yet.