From ea575f607438b74a2e19d0e57880e2e3bb429759 Mon Sep 17 00:00:00 2001
From: xamgore <xamgore@ya.ru>
Date: Fri, 6 May 2016 17:33:25 +0300
Subject: [PATCH] Make `mail exists` function name more sensible

+ Fix types
---
 ~dev_rating/application/classes/Account.php          |  8 +++-----
 .../application/classes/Controller/Handler/Sign.php  |  2 +-
 ~dev_rating/application/classes/Model/Account.php    | 12 ++++++------
 3 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/~dev_rating/application/classes/Account.php b/~dev_rating/application/classes/Account.php
index 985c5c0f7..0b87b7728 100644
--- a/~dev_rating/application/classes/Account.php
+++ b/~dev_rating/application/classes/Account.php
@@ -100,13 +100,11 @@ class Account
     }
 
     public static function doesLoginExist($login) {
-        $login_count = Model_Account::checkAccountExistence($login, 'login');
-        return $login_count > 0;
+        return Model_Account::checkAccountExistenceBy('login', $login);
     }
 
-    public static function isMailValid($email) {
-        $email_count = Model_Account::checkAccountExistence($email, 'email');
-        return $email_count > 0;
+    public static function doesEmailExist($email) {
+        return Model_Account::checkAccountExistenceBy('email', $email);
     }
 
 
diff --git a/~dev_rating/application/classes/Controller/Handler/Sign.php b/~dev_rating/application/classes/Controller/Handler/Sign.php
index 4f40f4bde..28ed3721b 100644
--- a/~dev_rating/application/classes/Controller/Handler/Sign.php
+++ b/~dev_rating/application/classes/Controller/Handler/Sign.php
@@ -65,7 +65,7 @@ class Controller_Handler_Sign extends Controller_Handler
         $this->post->rule('email', 'not_empty')->rule('email', 'email');
 
         if ($this->post->check()) {
-            if (Account::isMailValid($_POST['email'])) {
+            if (Account::doesEmailExist($_POST['email'])) {
                 Account::createRecoveryRequest($_POST['email']);
                 $res['success'] = true;
             } else {
diff --git a/~dev_rating/application/classes/Model/Account.php b/~dev_rating/application/classes/Model/Account.php
index c33d73f5d..3ba2085ff 100644
--- a/~dev_rating/application/classes/Model/Account.php
+++ b/~dev_rating/application/classes/Model/Account.php
@@ -95,14 +95,14 @@ class Model_Account extends Model
     }
 
     /**
-     * @param string $data
      * @param string $type 'login','email' or 'code'
-     * @return int
+     * @param string $value
+     * @return bool
      */
-    public static function checkAccountExistence($data, $type) {
-        $sql = "SELECT `CheckAccountExistence`(:data, :type) AS Num;";
-        return DB::query(Database::SELECT, $sql)
-            ->param(':data', $data)
+    public static function checkAccountExistenceBy($type, $value) {
+        $sql = "SELECT `CheckAccountExistence`(:value, :type) AS Num;";
+        return (bool) DB::query(Database::SELECT, $sql)
+            ->param(':value', $value)
             ->param(':type', $type)
             ->execute()->get('Num');
     }
-- 
GitLab