From f0174dd56a0c1d5b0e438d545529fffb9864d8c3 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 8 Jan 2017 21:33:26 +0100 Subject: [PATCH] Add NPS --- Business/Marketing/NetPromoterScore.php | 91 +++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 Business/Marketing/NetPromoterScore.php diff --git a/Business/Marketing/NetPromoterScore.php b/Business/Marketing/NetPromoterScore.php new file mode 100644 index 000000000..a4be85a10 --- /dev/null +++ b/Business/Marketing/NetPromoterScore.php @@ -0,0 +1,91 @@ + + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace phpOMS\Business\Marketing; + +/** + * Net Promoter Score + * + * @category Framework + * @package phpOMS\Business + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class NetPromoterScore { + /** + * Score values + * + * @var int[] + * @since 1.0.0 + */ + private $scores = []; + + /** + * Constructor. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function __construct() { + + } + + /** + * Add score. + * + * @param int $score Net promoter score + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function add(int $score) /* : void */ + { + $this->scores[] = $score; + } + + /** + * Get total NPS. + * + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getScore() : int + { + $promoters = 0; + $passives = 0; + $detractors = 0; + + foreach($this->scores as $score) { + if($score > 8) { + $promoters++; + } elseif($score > 6) { + $passives++; + } else { + $detractors++; + } + } + + $total = $promoters + $passives + $detractors; + + return ((int) ($promoters / $total)) - ((int) ($detractors / $total)); + } +} \ No newline at end of file