| Conditions | 6 | 
| Paths | 12 | 
| Total Lines | 59 | 
| Code Lines | 42 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php | ||
| 29 | 	public function loadLastContext($where = array(), $order = array(), $limit = array()) {	 | ||
| 30 | 		$qr = $this->database->prepare('SELECT * FROM ranking WHERE faction = 1 ORDER BY dRanking DESC LIMIT 1'); | ||
| 31 | $qr->execute(); | ||
| 32 | $aw = $qr->fetch(); | ||
| 33 | $rRanking = $aw['id']; | ||
| 34 | |||
| 35 | # add the rRanking to the WHERE clause | ||
| 36 | $where['rRanking'] = $rRanking; | ||
| 37 | |||
| 38 | $formatWhere = Utils::arrayToWhere($where); | ||
| 39 | $formatOrder = Utils::arrayToOrder($order); | ||
| 40 | $formatLimit = Utils::arrayToLimit($limit); | ||
| 41 | |||
| 42 | 		$qr = $this->database->prepare('SELECT * | ||
| 43 | FROM factionRanking AS fr | ||
| 44 | ' . $formatWhere . ' | ||
| 45 | ' . $formatOrder . ' | ||
| 46 | ' . $formatLimit | ||
| 47 | ); | ||
| 48 | |||
| 49 | 		foreach($where AS $v) { | ||
| 50 | 			if (is_array($v)) { | ||
| 51 | 				foreach ($v as $p) { | ||
| 52 | $valuesArray[] = $p; | ||
| 53 | } | ||
| 54 | 			} else { | ||
| 55 | $valuesArray[] = $v; | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | 		if(empty($valuesArray)) { | ||
| 60 | $qr->execute(); | ||
| 61 | 		} else { | ||
| 62 | $qr->execute($valuesArray); | ||
| 63 | } | ||
| 64 | |||
| 65 | 		while($aw = $qr->fetch()) { | ||
| 66 | $fr = new FactionRanking(); | ||
| 67 | |||
| 68 | $fr->id = $aw['id']; | ||
| 69 | $fr->rRanking = $aw['rRanking']; | ||
| 70 | $fr->rFaction = $aw['rFaction']; | ||
| 71 | $fr->points = $aw['points']; | ||
| 72 | $fr->pointsPosition = $aw['pointsPosition']; | ||
| 73 | $fr->pointsVariation = $aw['pointsVariation']; | ||
| 74 | $fr->newPoints = $aw['newPoints']; | ||
| 75 | $fr->general = $aw['general']; | ||
| 76 | $fr->generalPosition = $aw['generalPosition']; | ||
| 77 | $fr->generalVariation = $aw['generalVariation']; | ||
| 78 | $fr->wealth = $aw['wealth']; | ||
| 79 | $fr->wealthPosition = $aw['wealthPosition']; | ||
| 80 | $fr->wealthVariation = $aw['wealthVariation']; | ||
| 81 | $fr->territorial = $aw['territorial']; | ||
| 82 | $fr->territorialPosition = $aw['territorialPosition']; | ||
| 83 | $fr->territorialVariation = $aw['territorialVariation']; | ||
| 84 | |||
| 85 | $currentT = $this->_Add($fr); | ||
| 86 | } | ||
| 87 | } | ||
| 88 | |||
| 192 | } |