Skip to content

Commit f32fef4

Browse files
committed
Cleaned up and formatted code - some adjustments to selected files
The following adjustments were made: - Formate source code - Remove trailing whitespaces - FIX Uncaught TypeError: count() - Tabulation characters should not be used (PHP:105) - Files should end with a newline (PHP:S113) - Mergeable "if" statements should be combined (PHP:S1066) - Modifiers should be declared in the correct order (PHP:S1124) - Boolean literals should not be redundant (PHP:S1125) - Use empty() to check whether the array is empty or not (PHP:S1155) - Unused local variables should be removed (PHP:S1481) - PHP keywords and constants "true", "false", "null" should be lower case (PHP:S1781) - Method visibility should be explicitly declared (PHP:S1784) - "elseif" keyword should be used in place of "else if" keywords (PHP:S1793) - Unused assignments should be removed (PHP:S1854) - Boolean checks should not be inverted (PHP:1940) - Jump statements should not be redundant (PHP:3626) - "default" clauses should be first or last (PHP:4524)
1 parent fc6ed73 commit f32fef4

55 files changed

Lines changed: 51975 additions & 55682 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lib/functions/APIKey.class.php

Lines changed: 99 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,100 @@
1-
<?php
2-
/*
3-
* TestLink Open Source Project - http://testlink.sourceforge.net/
4-
*
5-
* Class that deals with API keys
6-
*
7-
* @filesource APIKey.class.php
8-
* @package TestLink
9-
* @author TestLink community
10-
* @copyright 2004-2011, TestLink community
11-
* @link http://www.teamst.org/index.php
12-
*
13-
* @internal revisions
14-
*/
15-
require_once dirname(__FILE__) . '/../../config.inc.php';
16-
require_once 'common.php';
17-
18-
class APIKey extends tlObjectWithDB
19-
{
20-
private $object_table = "";
21-
22-
public function __construct()
23-
{
24-
$db = null;
25-
doDBConnect($db);
26-
parent::__construct($db);
27-
$this->object_table = $this->tables["users"];
28-
}
29-
30-
31-
/**
32-
*
33-
* @param int $userID
34-
* @return mixed tl::OK / tl::ERROR
35-
*/
36-
public function addKeyForUser($userID)
37-
{
38-
$query = "UPDATE {$this->object_table} " .
39-
" SET script_key='" . $this->generateKey() . "' " .
40-
" WHERE id='".intval($userID)."'";
41-
$result = $this->db->exec_query($query);
42-
43-
if ($result)
44-
{
45-
$this->dbID = $this->db->insert_id();
46-
}
47-
return $result ? tl::OK : tl::ERROR;
48-
}
49-
50-
51-
/**
52-
*
53-
* @return string md5 hash of a string
54-
*/
55-
private function generateKey()
56-
{
57-
$key = '';
58-
59-
for($i=0; $i<8; $i++)
60-
{
61-
$key .= mt_rand();
62-
}
63-
64-
return md5($key);
65-
}
66-
67-
68-
/**
69-
*
70-
* @param int $userID
71-
* @return $key
72-
*/
73-
public function getAPIKey($userID)
74-
{
75-
$key=null;
76-
$key_map=$this->getAPIKeys($userID);
77-
78-
if( !is_null($key_map) )
79-
{
80-
$key = $key_map[$userID];
81-
}
82-
83-
return $key;
84-
}
85-
86-
87-
/**
88-
*
89-
* @param int $userID [userID]=default null => all APIkeys
90-
* @return array associative array[userID]=script_key
91-
*/
92-
public function getAPIKeys($userID=null)
93-
{
94-
$query = "SELECT id, script_key " .
95-
" FROM {$this->object_table} " ;
96-
97-
if( is_null($userID) )
98-
{
99-
$whereClause = " WHERE script_key IS NOT NULL";
100-
}
101-
else
102-
{
103-
$whereClause = " WHERE id=" . intval($userID);
104-
}
105-
$query .= $whereClause;
106-
107-
$rs = $this->db->fetchColumnsIntoMap($query, 'id', 'script_key');
108-
return $rs;
109-
}
110-
}
1+
<?php
2+
/*
3+
* TestLink Open Source Project - http://testlink.sourceforge.net/
4+
*
5+
* Class that deals with API keys
6+
*
7+
* @filesource APIKey.class.php
8+
* @package TestLink
9+
* @author TestLink community
10+
* @copyright 2004-2011, TestLink community
11+
* @link http://www.teamst.org/index.php
12+
*
13+
* @internal revisions
14+
*/
15+
require_once dirname(__FILE__) . '/../../config.inc.php';
16+
require_once 'common.php';
17+
18+
class APIKey extends tlObjectWithDB
19+
{
20+
21+
private $object_table = "";
22+
23+
public function __construct()
24+
{
25+
$db = null;
26+
doDBConnect($db);
27+
parent::__construct($db);
28+
$this->object_table = $this->tables["users"];
29+
}
30+
31+
/**
32+
*
33+
* @param int $userID
34+
* @return mixed tl::OK / tl::ERROR
35+
*/
36+
public function addKeyForUser($userID)
37+
{
38+
$query = "UPDATE {$this->object_table} " . " SET script_key='" . $this->generateKey() . "' " . " WHERE id='" . intval($userID) . "'";
39+
$result = $this->db->exec_query($query);
40+
41+
if ($result) {
42+
$this->dbID = $this->db->insert_id();
43+
}
44+
return $result ? tl::OK : tl::ERROR;
45+
}
46+
47+
/**
48+
*
49+
* @return string md5 hash of a string
50+
*/
51+
private function generateKey()
52+
{
53+
$key = '';
54+
55+
for ($i = 0; $i < 8; $i ++) {
56+
$key .= mt_rand();
57+
}
58+
59+
return md5($key);
60+
}
61+
62+
/**
63+
*
64+
* @param int $userID
65+
* @return $key
66+
*/
67+
public function getAPIKey($userID)
68+
{
69+
$key = null;
70+
$key_map = $this->getAPIKeys($userID);
71+
72+
if (! is_null($key_map)) {
73+
$key = $key_map[$userID];
74+
}
75+
76+
return $key;
77+
}
78+
79+
/**
80+
*
81+
* @param int $userID
82+
* [userID]=default null => all APIkeys
83+
* @return array associative array[userID]=script_key
84+
*/
85+
public function getAPIKeys($userID = null)
86+
{
87+
$query = "SELECT id, script_key " . " FROM {$this->object_table} ";
88+
89+
if (is_null($userID)) {
90+
$whereClause = " WHERE script_key IS NOT NULL";
91+
} else {
92+
$whereClause = " WHERE id=" . intval($userID);
93+
}
94+
$query .= $whereClause;
95+
96+
$rs = $this->db->fetchColumnsIntoMap($query, 'id', 'script_key');
97+
return $rs;
98+
}
99+
}
111100
?>

0 commit comments

Comments
 (0)