3. (Ex) PlanDuTalk
• Prendre un applicatif de mauvaise qualité
• Le placer sous surveillance Sonar
• Utiliser Sonar comme guide qualité
• Améliorer la qualité de l’applicatif
• Suivre les progrès avec Sonar
4. PlanDuTalk
• Prendre un applicatif de mauvaise qualité
• Le placer sous surveillance Sonar
• Montrer Sonar
• Préparer l’applicatif pour le refactoring
• Paramétrer Sonar pour le refactoring
• Début du refactoring
• Afficher les amélioration dans Sonar
5. (Ex) ButsDuTalk
• Introduire Sonar pour PHP
• Parler bonnes pratiques XP
• Montrer des techniques pour le « legacy code »
6. (Ex) ButsDuTalk
• Introduire Sonar pour PHP
• Parler bonnes pratiques XP
• Montrer des techniques pour le « legacy code »
• … s’amuser avec l’exemple de « revamping »
7. ButsDuTalk
• Introduire Sonar pour PHP
• Parler bonnes pratiques XP
• Montrer des techniques pour le « legacy code »
• … s’amuser avec l’exemple de « revamping »
8. Exemple
• Petit projet (3-6k LOC)
• Vieux code (à la « PHP3/4 »)
• Recherche Sourceforge de projets s’arretant ~2006
• Intéressant pour moi
• And the winner is…
11. OpeningTheBox
class class_mysql{ // PSR0 ?
function class_mysql() {
global $CONFIG;
$this->host = $CONFIG['mysql']['host'];
$this->user = $CONFIG['mysql']['user'];
$this->pass = $CONFIG['mysql']['pass'];
$this->dbase = $CONFIG['mysql']['dbase'];
return true;
}
function db_con(){
$db = mysql_connect($this->host, $this->user, $this->pass)
or die ("verbindung $this->user@$this->host fehlgeschlagen");
12. DidYouSayDecoupled?
#status 0: Offline
# ...
# status: 10 Running Game
class class_risk{
function get_soapobject() {
global $CONFIG;
require_once 'SOAP/Client.php'; // aucun répertoire “SOAP”…
function soapUpdateNumOnline($numonline) {
global $CONFIG;
13. DidYouSaySRP?
Méthodes de class_risk :
• 7 méthodes contenant« soap »
• 21 méthodes contenant « display »
• ~15 méthodes d’action
• 4 méthodes contenant « By »
• …
• 57 méthodes au total
• 1648 LOC au total
14. DidYouSaySoC?
function display_win() {
$cdb = new class_mysql;
$cdb->select("SELECT CurrentGame FROM risk_config");
$row = $cdb->fetchArray();
if ($row['CurrentGame'] != "Complete") {
header("Location: index.php");
}
$cdb->select("SELECT username, color FROM risk_players WHERE
status='10'");
$row = $cdb->fetchArray();
$r = "<h2>Game Over</h2><center><br><br><br><font color='".$row['color']."'
class="wintext">".$row['username']."wins!<br><br><br></font></center>";
return $r;
}
20. SonarDontImpliesMaven
• Depuis la 2.6, Java Runner
• Installation en 2 minutes
http://docs.codehaus.org/display/SONAR/Analyse+with+a+simple+Java+
Runner
• Fichier sonar-project.properties
# required metadata
sonar.projectKey=my:risk
sonar.projectName=PHP Risk
sonar.projectVersion=0.3
# path to source directories (required)
sources=source
# path to test source directories (optional)
tests=test
# The value of the property must be the key of the language
sonar.language=php
# PHP plugin specific parameters
sonar.phpUnit.shouldRun=false
sonar.dynamicAnalysis=false
21. FirstSonarRun
• Lancer « sonar-runner » à la racine du projet
• Le projet apparait dans l’interface web
25. FastFunctionalTesting
Au début le calque remplacera les TUA
Dans le cycle TDD!
Doit être
RAPIDE
Selenium ne convient pas
Les solutions spécifiques à un framework non plus
26. BehatMink
Behat : Framework BDD (style Cucumber)
Mink : Framework pour les tests de recette
• Abstraction du navigateur et du driver
• Drivers disponibles :
• Goutte (headless HTTP)
• Sahi, Selenium (navigateur)
• Zombie (headless javascript!)
27. GoutteScenario
Feature: Register
In order to play the risk game when I want
As a site visitor
I need to become a site user
Scenario: Register as a new user
Given I am on "register.php"
When I fill in "username" with "blacksun"
And I fill in "password" with "password"
And I fill in "confirmpassword" with "password"
And I fill in "email" with "toto@example.com"
And I press "Register"
Then I should see "added"
28. ZombieScenario
Feature: Register
In order to play the risk game when I want
As a site visitor
I need to become a site user
@mink:zombie
Scenario: Register as a new user
Given I am on "register.php"
When I fill in "username" with "blacksun"
And I fill in "password" with "password"
And I fill in "confirmpassword" with "password"
And I fill in "email" with "toto@example.com"
And I press "Register"
Then I should see "added"
32. DynamicAnalysis
• Retour sur sonar-project.properties
# required metadata
sonar.projectKey=my:risk
sonar.projectName=PHP Risk
sonar.projectVersion=0.3
# path to source directories (required)
sources=source
# path to test source directories (optional)
tests=test
# The value of the property must be the key of the language
sonar.language=php
# PHP plugin specific parameters
sonar.phpUnit.mainTestClass=test/functional/BehatTest.php
sonar.dynamicAnalysis=true
33. Adjusting
• Je fixe les EOL dans class_risk.php
• Je sépare le composant xajax dans un répertoire xajax/
• Je mets les contrôleurs de page et les assets dans www/
39. SonarPHPState
Version 0.6 : hier !
• Introduction des profils par défaut
• Prise en compte de toute propriété PHPCS
Version 0.7 : décembre
• Prise en compte de toute règle PHPCS et PHPMD
• Correction d’un problème très gênant sur le nommage
des fichiers
• Automatisation Import/Export des règles
40. BarackObamaFeatures
Version 1.0 et +
• Gestion des fichiers « plats »
• Synchronisation avec Eclipse (plugin Eclipse)
• Compatibilité avec d’autres plugins Sonar
• Utilisation automatique avec un service ci-clould
• Nemo pour php
41. SonarPHPPointers
• Les documents d’installation déjà cités
• Documentation officielle du plugin
• http://docs.codehaus.org/display/SONAR/PHP+Plugin
• Billets de blog et articles (certains « historiques »)
• « Continuous Integration with Sonar » S. Marek php|architect Avril 2011
• http://www.phparch.com/magazine/2011-2/april/
• http://www.blacksun.fr/2009/12/sonar-for-php-is-on-its-way/
• http://akrambenaissi.wordpress.com/2011/02/23/le-plugin-sonar-php
• http://criticallog.thornet.net/2010/11/22/sonar-for-php-coming/
42. PHPRiskState?
Court terme
• Continuer le refactoring
• (en faire la présentation)
• Publier
• Améliorer l’usabilité
Moyen terme?
• Plus de paramètres (règles, cartes, …)
• Nouvelles mappes
• Plusieurs AI
• Les AI peuvent jouer à distance via REST