Skip to content

Commit 00e179d

Browse files
author
jdlabails
committed
Take copy paste and security checker into the score
1 parent e3830d8 commit 00e179d

7 files changed

Lines changed: 76 additions & 15 deletions

File tree

DependencyInjection/Configuration.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public function getConfigTreeBuilder()
6969
->children()
7070
->booleanNode('enable')->defaultTrue()->end()
7171
->scalarNode('csWeight')->defaultValue('100')->cannotBeEmpty()->end()
72+
->scalarNode('cpWeight')->defaultValue('100')->cannotBeEmpty()->end()
73+
->scalarNode('scWeight')->defaultValue('100')->cannotBeEmpty()->end()
7274
->scalarNode('testWeight')->defaultValue('100')->cannotBeEmpty()->end()
7375
->scalarNode('locWeight')->defaultValue('100')->cannotBeEmpty()->end()
7476
->scalarNode('projectSize')->defaultValue('medium')->cannotBeEmpty()->end()

Entities/Analyze.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ class Analyze
2929
*/
3030
private $csSuccess;
3131

32+
/**
33+
* @var boolean
34+
*/
35+
private $cpSuccess;
36+
3237
/**
3338
* @var boolean
3439
*/
@@ -223,6 +228,29 @@ public function getCsSuccess()
223228
return $this->csSuccess;
224229
}
225230

231+
/**
232+
* Set cpSuccess
233+
*
234+
* @param boolean $cpSuccess
235+
* @return analyze
236+
*/
237+
public function setCpSuccess($cpSuccess)
238+
{
239+
$this->cpSuccess = $cpSuccess;
240+
241+
return $this;
242+
}
243+
244+
/**
245+
* Get cpSuccess
246+
*
247+
* @return boolean
248+
*/
249+
public function getCpSuccess()
250+
{
251+
return $this->cpSuccess;
252+
}
253+
226254
/**
227255
* Set securitySuccess
228256
*

Resources/translations/messages.en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ score.popContent.fitWeighting: You can adjust the weighting of these elements in
1414
score.popContent.currentSet: "You are currently set as:"
1515
score.popContent.weight: weight
1616
score.popContent.csWeight: Code sniffer weight
17+
score.popContent.cpWeight: Copy paste weight
18+
score.popContent.scWeight: Security checker weight
1719
score.popContent.testWeight: Tests weight
1820
score.popContent.sizeWeight: Size weight
1921
score.popContent.scale: Project scale

Resources/translations/messages.fr.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ score.popContent.sizeProject: Taille du projet
1313
score.popContent.fitWeighting: Vous pouvez adapter la pondération de ces éléments dans le param.yml.
1414
score.popContent.currentSet: "Vous êtes paramétrés comme suit :"
1515
score.popContent.csWeight: Pondération de code sniffer
16+
score.popContent.cpWeight: Pondération de copy paste
17+
score.popContent.scWeight: Pondération de security checker
1618
score.popContent.testWeight: Pondération des tests
1719
score.popContent.sizeWeight: Pondération de la taille
1820
score.popContent.scale: Echelle du projet

Resources/views/Main/header.html.twig

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
3636
<ul>
3737
<li>Code Sniffer score</li>
38-
<li>Tests status X code coverage</li>
38+
<li>Copy paste score</li>
39+
<li>Security checker score</li>
40+
<li>Tests status x code coverage</li>
3941
<li>{% trans %}score.popContent.sizeProject{%endtrans %}</li>
4042
</ul>
4143
{% trans %}score.popContent.fitWeighting{%endtrans %}
@@ -46,6 +48,14 @@
4648
{% trans %}score.popContent.csWeight{%endtrans %} :
4749
{{ projectAnalyzer.getScoreWeightParam('csWeight')}}
4850
</li>
51+
<li>
52+
{% trans %}score.popContent.cpWeight{%endtrans %} :
53+
{{ projectAnalyzer.getScoreWeightParam('cpWeight')}}
54+
</li>
55+
<li>
56+
{% trans %}score.popContent.scWeight{%endtrans %} :
57+
{{ projectAnalyzer.getScoreWeightParam('scWeight')}}
58+
</li>
4959
<li>
5060
{% trans %}score.popContent.testWeight{%endtrans %} :
5161
{{ projectAnalyzer.getScoreWeightParam('testWeight')}}

Tests/Traits/ScoreCalculatorTest.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,16 @@ public function testGetScoreWeightParam()
4444
$this->assertEquals($this->getScoreWeightParam('locWeight'), 100);
4545
}
4646

47-
/**
48-
* Test du formatage des dates
49-
*/
5047
public function testCalculateScore()
5148
{
5249
// resultats de l'analyse
5350
$this->oAnalyze = new Analyze();
5451
$this->oAnalyze
55-
->setCov('100%')
52+
->setCov(100)
53+
->setCpSuccess(false)
5654
->setCsSuccess(true)
57-
->setLoc(10000)
55+
->setSecuritySuccess(false)
56+
->setLoc(8564)
5857
->setTuSuccess(true)
5958
;
6059

@@ -66,12 +65,21 @@ public function testCalculateScore()
6665
// scoring enable
6766
$this->parameters['score'] = [
6867
'enable' => true,
69-
'testWeight' => '100',
70-
'locWeight' => '100',
71-
'csWeight' => '100',
68+
'testWeight' => '20',
69+
'cpWeight' => '30',
70+
'scWeight' => '40',
71+
'locWeight' => '50',
72+
'csWeight' => '60',
7273
];
7374

75+
$note =
76+
60 + // cs
77+
20 + // test
78+
8564 * 50 / 10000; // loc
79+
$divide = (20 + 30 + 40 + 50 + 60) / 20;
80+
$score = round(($note / $divide), 2);
81+
7482
$this->calculateScore();
75-
$this->assertEquals($this->oAnalyze->getScore(), 14.67);
83+
$this->assertEquals($this->oAnalyze->getScore(), $score);
7684
}
7785
}

Traits/ScoreCalculator.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ trait ScoreCalculator
1515

1616
/**
1717
* Return true if score is enable by the config file
18-
* @return type
18+
* @return boolean
1919
*/
2020
public function isScoreEnable()
2121
{
@@ -35,10 +35,14 @@ protected function calculateScore()
3535

3636
$loc = (int) $this->oAnalyze->getLoc();
3737
$cs = (int) ($this->oAnalyze->getCsSuccess() === true);
38+
$cp = (int) ($this->oAnalyze->getCpSuccess() === true);
39+
$sc = (int) ($this->oAnalyze->getSecuritySuccess() === true);
3840
$test = (int) ($this->oAnalyze->getTuSuccess() === true);
3941
$cc = (float) $this->oAnalyze->getCov();
4042

4143
$csWeight = $this->getScoreWeightParam('csWeight');
44+
$cpWeight = $this->getScoreWeightParam('cpWeight');
45+
$scWeight = $this->getScoreWeightParam('scWeight');
4246
$testWeight = $this->getScoreWeightParam('testWeight');
4347
$locWeight = $this->getScoreWeightParam('locWeight');
4448

@@ -53,22 +57,27 @@ protected function calculateScore()
5357
$maxSize = 100000;
5458
}
5559

56-
$note = $cs * $csWeight + $test * $testWeight * ($cc / 100) + $loc * $locWeight / $maxSize;
57-
$divide = ($csWeight + $testWeight + $locWeight) / 20;
60+
$note =
61+
$cp * $cpWeight +
62+
$sc * $scWeight +
63+
$cs * $csWeight +
64+
$test * $testWeight * ($cc / 100) +
65+
$loc * $locWeight / $maxSize;
66+
$divide = ($csWeight + $scWeight + $cpWeight + $testWeight + $locWeight) / 20;
5867
$score = round(($note / $divide), 2);
5968

6069
$this->oAnalyze->setScore($score);
6170
}
6271

6372
/**
6473
* Return weight of the given parameter
65-
* @param type $name
74+
* @param string $name
6675
* @return int
6776
*/
6877
public function getScoreWeightParam($name)
6978
{
7079
$weight = $this->getParam('score', $name);
71-
if (!is_int($weight)) {
80+
if (!is_numeric($weight)) {
7281
return 100;
7382
}
7483

0 commit comments

Comments
 (0)