Skip to content
This repository has been archived by the owner on Jul 15, 2020. It is now read-only.

Commit

Permalink
Better comment length calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
petk committed Jun 5, 2016
1 parent 00a7e87 commit 830039e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/config/points.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Points configuration for Expression Language component evaluation

# Additional points for length of comment or reply.
points_message_length: 'strlen(message) > 100 ? 1 : 0'
points_message_length: 'floor(strlen(message)/50)'

# Points for number of likes on comment or reply
points_for_likes: '(likes > 100) ? 11 : ceil(likes / 10)'
Expand Down Expand Up @@ -40,8 +40,8 @@ urls:
- ['stackoverflow.com', 5]
- ['phpunit.de', 5]
- ['php-fig.org', 5]
- ['w3schools.com', -10]
- ['lmgtfy.com', -10]
- ['w3schools.com', -20]

# Points for topics from admins
points_for_admin_topics: '(topic.getUser().getId() in admins) ? 5 : 0'
9 changes: 9 additions & 0 deletions src/ExpressionLanguage/NumberExpressionLanguageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ public function getFunctions()

return ceil($num);
}),
new ExpressionFunction('floor', function ($num) {
return sprintf('(is_numeric(%1$s) ? floor(%1$s) : %1$s)', $num);
}, function ($arguments, $num) {
if (!is_numeric($num)) {
return $num;
}

return floor($num);
}),
];
}
}
4 changes: 4 additions & 0 deletions tests/PointsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ public function commentsAndRepliesProvider()
['Lorem ipsum dolor sit amet.', 0, 1],
['Lorem ipsum dolor sit amet', 5, 2],
['Lorem ipsum dolor sit amet', 11, 3],
[str_repeat("a", 10), 0, 1],
[str_repeat("a", 50), 0, 2],
[str_repeat("a", 100), 0, 3],
[str_repeat("a", 2000), 0, 41],
];
}

Expand Down

0 comments on commit 830039e

Please sign in to comment.