Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
TelegramBot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
TelegramBot
Commits
1ff9b4f9
Unverified
Commit
1ff9b4f9
authored
Oct 11, 2016
by
Armando Lüscher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify Keyboard entities and tests to remove duplicate code.
Small optimisation for Chat entity.
parent
1cfa4779
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
9 additions
and
38 deletions
+9
-38
Chat.php
src/Entities/Chat.php
+1
-1
InlineKeyboard.php
src/Entities/InlineKeyboard.php
+0
-30
Keyboard.php
src/Entities/Keyboard.php
+4
-3
InlineKeyboardTest.php
tests/unit/Entities/InlineKeyboardTest.php
+2
-2
KeyboardTest.php
tests/unit/Entities/KeyboardTest.php
+2
-2
No files found.
src/Entities/Chat.php
View file @
1ff9b4f9
...
...
@@ -36,7 +36,7 @@ class Chat extends Entity
$id
=
$this
->
getId
();
$type
=
$this
->
getType
();
if
(
!
$type
&&
$id
!==
0
)
{
if
(
!
$type
)
{
$id
>
0
&&
$this
->
type
=
'private'
;
$id
<
0
&&
$this
->
type
=
'group'
;
}
...
...
src/Entities/InlineKeyboard.php
View file @
1ff9b4f9
...
...
@@ -10,8 +10,6 @@
namespace
Longman\TelegramBot\Entities
;
use
Longman\TelegramBot\Exception\TelegramException
;
/**
* Class InlineKeyboard
*
...
...
@@ -19,32 +17,4 @@ use Longman\TelegramBot\Exception\TelegramException;
*/
class
InlineKeyboard
extends
Keyboard
{
/**
* {@inheritdoc}
*/
public
function
__construct
(
$data
=
[])
{
$data
=
call_user_func_array
([
$this
,
'createFromParams'
],
func_get_args
());
parent
::
__construct
(
$data
);
}
/**
* {@inheritdoc}
*/
protected
function
validate
()
{
$inline_keyboard
=
$this
->
getProperty
(
'inline_keyboard'
);
if
(
$inline_keyboard
!==
null
)
{
if
(
!
is_array
(
$inline_keyboard
))
{
throw
new
TelegramException
(
'Inline Keyboard field is not an array!'
);
}
foreach
(
$inline_keyboard
as
$item
)
{
if
(
!
is_array
(
$item
))
{
throw
new
TelegramException
(
'Inline Keyboard subfield is not an array!'
);
}
}
}
}
}
src/Entities/Keyboard.php
View file @
1ff9b4f9
...
...
@@ -178,16 +178,17 @@ class Keyboard extends Entity
*/
protected
function
validate
()
{
$keyboard
=
$this
->
getProperty
(
'keyboard'
);
$keyboard_type
=
$this
->
getKeyboardType
();
$keyboard
=
$this
->
getProperty
(
$keyboard_type
);
if
(
$keyboard
!==
null
)
{
if
(
!
is_array
(
$keyboard
))
{
throw
new
TelegramException
(
'Keyboard
field is not an array!'
);
throw
new
TelegramException
(
$keyboard_type
.
'
field is not an array!'
);
}
foreach
(
$keyboard
as
$item
)
{
if
(
!
is_array
(
$item
))
{
throw
new
TelegramException
(
'Keyboard
subfield is not an array!'
);
throw
new
TelegramException
(
$keyboard_type
.
'
subfield is not an array!'
);
}
}
}
...
...
tests/unit/Entities/InlineKeyboardTest.php
View file @
1ff9b4f9
...
...
@@ -36,7 +36,7 @@ class InlineKeyboardTest extends TestCase
/**
* @expectedException \Longman\TelegramBot\Exception\TelegramException
* @expectedExceptionMessage
Inline K
eyboard field is not an array!
* @expectedExceptionMessage
inline_k
eyboard field is not an array!
*/
public
function
testInlineKeyboardDataMalformedField
()
{
...
...
@@ -45,7 +45,7 @@ class InlineKeyboardTest extends TestCase
/**
* @expectedException \Longman\TelegramBot\Exception\TelegramException
* @expectedExceptionMessage
Inline K
eyboard subfield is not an array!
* @expectedExceptionMessage
inline_k
eyboard subfield is not an array!
*/
public
function
testInlineKeyboardDataMalformedSubfield
()
{
...
...
tests/unit/Entities/KeyboardTest.php
View file @
1ff9b4f9
...
...
@@ -25,7 +25,7 @@ class KeyboardTest extends TestCase
{
/**
* @expectedException \Longman\TelegramBot\Exception\TelegramException
* @expectedExceptionMessage
K
eyboard field is not an array!
* @expectedExceptionMessage
k
eyboard field is not an array!
*/
public
function
testKeyboardDataMalformedField
()
{
...
...
@@ -34,7 +34,7 @@ class KeyboardTest extends TestCase
/**
* @expectedException \Longman\TelegramBot\Exception\TelegramException
* @expectedExceptionMessage
K
eyboard subfield is not an array!
* @expectedExceptionMessage
k
eyboard subfield is not an array!
*/
public
function
testKeyboardDataMalformedSubfield
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment