Skip to content

Commit af6f4df

Browse files
committed
Fixed coding standart issues, improved readme
1 parent 999ee2e commit af6f4df

File tree

12 files changed

+188
-61
lines changed

12 files changed

+188
-61
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ before_script:
3030
- mysql -e 'create database telegrambot; use telegrambot; source structure.sql;'
3131

3232
script:
33-
- vendor/bin/phpunit
34-
- vendor/bin/phpcs --report=full --extensions=php -np --standard=build/phpcs .
33+
- ./vendor/bin/phpunit
34+
- ./vendor/bin/phpcs --standard=phpcs.xml -snp --encoding=utf-8 src/ --report-width=150

CONTRIBUTING.md

+3-11
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ Before you contribute code to php-telegram-bot, please make sure it conforms to
55

66
cd php-telegram-bot
77
composer update
8-
vendor/bin/phpcs --report=full --extensions=php -np --standard=build/phpcs .
8+
./vendor/bin/phpcs --standard=phpcs.xml -sp --encoding=utf-8 src/ --report-width=150
99

1010
Which should give you no output, indicating that there are no coding standard errors. And then:
1111

12-
vendor/bin/phpunit
12+
./vendor/bin/phpunit
1313

1414
Which should give you no failures or errors. You can ignore any skipped tests as these are for external tools.
1515

@@ -30,7 +30,7 @@ Further code convention adopted
3030

3131
- Each method and class is documented with a docblock
3232

33-
Example for a function or methods:
33+
Example for a function or methods:
3434
```
3535
/**
3636
* Get formatted date
@@ -52,11 +52,3 @@ Example for a function or methods:
5252
* file that was distributed with this source code.
5353
*/
5454
```
55-
- No empty line after class declaration
56-
- No empty line after `<?php`
57-
- Last element of a multi-line array must be followed by a comma
58-
- One empty line after the docblock header
59-
- Array elements and `use` statements should be written in a logical order, preferrably alphabetically
60-
- Use [] instead of array()
61-
- Use single quotes (`'`) for string
62-
- Leave space in front and behind the concatenation operator `.`

README.md

+54-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,49 @@
1111

1212
A Telegram Bot based on the official [Telegram Bot API](https://core.telegram.org/bots/api)
1313

14+
## Table of Contents
15+
- [Introduction](#introduction)
16+
- [Instructions](#instructions)
17+
- [Create your first bot](#create-your-first-bot)
18+
- [Require this package with Composer](#require-this-package-with-composer)
19+
- [Choose how to retrieve Telegram updates](#choose-how-to-retrieve-telegram-updates)
20+
- [Webhook installation](#webhook-installation)
21+
- [Self Signed Certificate](#self-signed-certificate)
22+
- [Unset Webhook](#unset-webhook)
23+
- [getUpdate installation](#getupdate-installation)
24+
- [Support](#support)
25+
- [Types](#types)
26+
- [Inline Query](#inline-query)
27+
- [Methods](#methods)
28+
- [Send Message](#send-message)
29+
- [Send Photo](#send-photo)
30+
- [Send Chat Action](#send-chat-action)
31+
- [getUserProfilePhoto](#getuserprofilephoto)
32+
- [getFile and dowloadFile](#getfile-and-dowloadfile)
33+
- [Send message to all active chats](#send-message-to-all-active-chats)
34+
- [Utils](#utils)
35+
- [MySQL storage (Recommended)](#mysql-storage-recommended)
36+
- [Channels Support](#channels-support)
37+
- [Commands](#commands)
38+
- [Predefined Commands](#predefined-commands)
39+
- [Custom Commands](#custom-commands)
40+
- [Commands Configuration](#commands-configuration)
41+
- [Admin Commands](#admin-commands)
42+
- [Set Admins](#set-admins)
43+
- [Channel Administration](#channel-administration)
44+
- [Upload and Download directory path](#upload-and-download-directory-path)
45+
- [Logging](#logging)
46+
- [Documentation](#documentation)
47+
- [Projects with this library](#projects-with-this-library)
48+
- [Troubleshooting](#troubleshooting)
49+
- [Contributing](#contributing)
50+
- [License](#license)
51+
- [Credits](#credits)
52+
53+
54+
55+
56+
1457

1558
## Introduction
1659

@@ -199,7 +242,7 @@ $result = $telegram->setWebHook($hook_url, $certificate_path);
199242

200243
Edit *example/unset.php* with your bot credentials and execute it.
201244

202-
## getUpdate installation
245+
### getUpdate installation
203246

204247
The MySQL database must be active!
205248

@@ -353,6 +396,8 @@ With [admin commands](#admin-commands) you can manage your channels directly wit
353396

354397
### Commands
355398

399+
#### Predefined Commands
400+
356401
The bot is able to recognise commands in a chat with multiple bots (/command@mybot).
357402
It can execute command triggering a chat event. Here's the list:
358403

@@ -375,6 +420,8 @@ Favourite number? **/1, /134**
375420

376421
**GenericmessageCommand.php** lets you handle any type of message.
377422

423+
#### Custom Commands
424+
378425
Maybe you would like to develop your own commands. A good practice is
379426
to store them outside *vendor/*. This can be done using:
380427

@@ -399,6 +446,9 @@ Enabling this feature, the admin bot can perform some super user commands like:
399446
- Send message to all chats */sendtoall*
400447
- List all the chats started with the bot */chats*
401448
- Post any content to your channels */sendtochannel* (NEW! see below how to configure it)
449+
450+
#### Set Admins
451+
402452
You can specify one or more admins with this option:
403453

404454
```php
@@ -417,7 +467,7 @@ To enable this feature follow these steps:
417467
```php
418468
$telegram->setCommandConfig('sendtochannel', ['your_channel' => ['@type_here_your_channel']]);
419469
```
420-
- If you want to manage more channels:
470+
- If you want to manage more channels:
421471
```php
422472
$telegram->setCommandConfig('sendtochannel', ['your_channel'=>['@type_here_your_channel', '@type_here_another_channel', '@and_so_on']]);
423473
```
@@ -431,7 +481,7 @@ $telegram->setDownloadPath('yourpath/Download');
431481
$telegram->setUploadPath('yourpath/Upload');
432482
```
433483

434-
### Logging
484+
## Logging
435485

436486
Thrown Exceptions are stored in *TelegramException.log* file (in the base directory).
437487

@@ -451,7 +501,7 @@ $telegram->setLogVerbosity(3);
451501

452502
## Documentation
453503

454-
Take a look at the repo [Wiki](https://github.com/akalongman/php-telegram-bot/wiki) for further information and tutorial!
504+
Take a look at the repo [Wiki](https://github.com/akalongman/php-telegram-bot/wiki) for further information and tutorials!
455505
Feel free to improve!
456506

457507
## Projects with this library

build/phpcs/ruleset.xml

-30
This file was deleted.

composer.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
}
3434
},
3535
"require-dev": {
36-
"phpunit/phpunit": "~4.1",
37-
"phpspec/phpspec": "~2.1",
38-
"squizlabs/php_codesniffer": "~2.3"
36+
"phpunit/phpunit": "~5.2",
37+
"squizlabs/php_codesniffer": "~2.5"
3938
}
4039
}

phpcs.xml

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ruleset name="pcsg-generated-ruleset">
3+
<description>PHP Code Sniffer</description>
4+
5+
<arg name="colors"/>
6+
7+
<rule ref="PSR2"/>
8+
9+
<rule ref="Generic.CodeAnalysis.EmptyStatement"/>
10+
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/>
11+
<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter"/>
12+
<rule ref="Generic.CodeAnalysis.JumbledIncrementer"/>
13+
<rule ref="Generic.CodeAnalysis.UnconditionalIfStatement"/>
14+
<rule ref="Generic.CodeAnalysis.UnnecessaryFinalModifier"/>
15+
16+
<rule ref="Generic.ControlStructures.InlineControlStructure"/>
17+
18+
<rule ref="Generic.Files.ByteOrderMark"/>
19+
<rule ref="Generic.Files.LineEndings"/>
20+
21+
<rule ref="Generic.Formatting.DisallowMultipleStatements"/>
22+
<rule ref="Generic.Formatting.SpaceAfterCast.NoSpace">
23+
<type>warning</type>
24+
</rule>
25+
<rule ref="Generic.Functions.CallTimePassByReference"/>
26+
<rule ref="Generic.Functions.FunctionCallArgumentSpacing"/>
27+
28+
<rule ref="Generic.Metrics.NestingLevel">
29+
<properties>
30+
<property name="nestingLevel" value="7"/>
31+
</properties>
32+
</rule>
33+
<rule ref="Generic.Metrics.CyclomaticComplexity">
34+
<properties>
35+
<property name="complexity" value="20"/>
36+
<property name="absoluteComplexity" value="40"/>
37+
</properties>
38+
</rule>
39+
<rule ref="Generic.Metrics.CyclomaticComplexity.TooHigh">
40+
<type>warning</type>
41+
</rule>
42+
<rule ref="Generic.Metrics.CyclomaticComplexity.MaxExceeded">
43+
<type>warning</type>
44+
</rule>
45+
46+
<rule ref="Generic.NamingConventions.ConstructorName"/>
47+
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
48+
<rule ref="Generic.NamingConventions.CamelCapsFunctionName"/>
49+
50+
<rule ref="Generic.PHP.DeprecatedFunctions"/>
51+
<rule ref="Generic.PHP.DisallowShortOpenTag"/>
52+
<rule ref="Generic.PHP.ForbiddenFunctions"/>
53+
<rule ref="Generic.PHP.LowerCaseConstant"/>
54+
<rule ref="Generic.PHP.NoSilencedErrors"/>
55+
56+
<rule ref="Generic.Strings.UnnecessaryStringConcat"/>
57+
58+
<rule ref="Generic.WhiteSpace.DisallowTabIndent"/>
59+
<rule ref="Generic.WhiteSpace.ScopeIndent"/>
60+
61+
<rule ref="Generic.Commenting.Todo.CommentFound">
62+
<message>Please review this TODO comment: %s</message>
63+
<type>warning</type>
64+
</rule>
65+
<rule ref="Generic.Commenting.Fixme.TaskFound">
66+
<message>Please review this FIXME comment: %s</message>
67+
<type>warning</type>
68+
</rule>
69+
70+
<rule ref="Generic.Files.LineLength">
71+
<properties>
72+
<property name="lineLimit" value="120"/>
73+
<property name="absoluteLineLimit" value="200"/>
74+
</properties>
75+
</rule>
76+
<rule ref="Generic.Files.LineLength">
77+
<exclude name="Generic.Files.LineLength.MaxExceeded"/>
78+
<exclude name="Generic.Files.LineLength.TooLong"/>
79+
</rule>
80+
<!--
81+
<rule ref="Generic.Files.LineLength.MaxExceeded">
82+
<message>Line contains %s chars, which is longer than the max limit of %s</message>
83+
<type>warning</type>
84+
</rule>
85+
<rule ref="Generic.Files.LineLength.TooLong">
86+
<message>Line longer than %s characters; contains %s characters</message>
87+
<type>warning</type>
88+
</rule> -->
89+
<rule ref="Generic.Classes.DuplicateClassName"/>
90+
91+
<rule ref="PEAR.Commenting.InlineComment"/>
92+
93+
<rule ref="PEAR.ControlStructures.MultiLineCondition"/>
94+
95+
<rule ref="PEAR.WhiteSpace.ObjectOperatorIndent"/>
96+
97+
<rule ref="MySource.PHP.EvalObjectFactory"/>
98+
<rule ref="MySource.PHP.GetRequestData"/>
99+
<!--
100+
<rule ref="MySource.PHP.ReturnFunctionValue"/>
101+
-->
102+
103+
<rule ref="Squiz.WhiteSpace.LogicalOperatorSpacing"/>
104+
<rule ref="Squiz.WhiteSpace.SemicolonSpacing"/>
105+
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines">
106+
<type>warning</type>
107+
</rule>
108+
<rule ref="Squiz.WhiteSpace.CastSpacing"/>
109+
<rule ref="Squiz.WhiteSpace.LanguageConstructSpacing"/>
110+
<!--
111+
<rule ref="Squiz.WhiteSpace.MemberVarSpacing"/>
112+
-->
113+
<rule ref="Squiz.WhiteSpace.OperatorSpacing"/>
114+
115+
<rule ref="Squiz.Scope.StaticThisUsage"/>
116+
117+
</ruleset>

src/Commands/AdminCommands/SendtochannelCommand.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public function execute()
236236
/**
237237
* {@inheritdoc}
238238
*/
239-
public function executeNoDB()
239+
public function executeNoDb()
240240
{
241241
$message = $this->getMessage();
242242
$text = trim($message->getText(true));
@@ -274,8 +274,7 @@ protected function publish(Message $message, $channel, $caption = null)
274274
if ($this->sendBack($message, $data)->isOk()) {
275275
$response = 'Message sent successfully to: ' . $channel;
276276
} else {
277-
$response =
278-
'Message not sent to: ' . $channel . "\n" .
277+
$response = 'Message not sent to: ' . $channel . "\n" .
279278
'- Does the channel exist?' . "\n" .
280279
'- Is the bot an admin of the channel?';
281280
}

src/Commands/Command.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function setUpdate(Update $update = null)
128128
public function preExecute()
129129
{
130130
if ($this->need_mysql && !($this->telegram->isDbEnabled() && DB::isDbConnected())) {
131-
return $this->executeNoDB();
131+
return $this->executeNoDb();
132132
}
133133
return $this->execute();
134134
}
@@ -145,7 +145,7 @@ abstract public function execute();
145145
*
146146
* @return Entities\ServerResponse
147147
*/
148-
public function executeNoDB()
148+
public function executeNoDb()
149149
{
150150
//Preparing message
151151
$message = $this->getMessage();

src/Commands/SystemCommands/GenericmessageCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class GenericmessageCommand extends SystemCommand
3333
*
3434
* @return boolean
3535
*/
36-
public function executeNoDB()
36+
public function executeNoDb()
3737
{
3838
//Do nothing
3939
return Request::emptyResponse();

src/Commands/UserCommands/CancelCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function execute()
5858
/**
5959
* {@inheritdoc}
6060
*/
61-
public function executeNoDB()
61+
public function executeNoDb()
6262
{
6363
return $this->hideKeyboard();
6464
}

src/Entities/Entity.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function getBotName()
2121
return $this->bot_name;
2222
}
2323

24-
public function toJSON()
24+
public function toJson()
2525
{
2626
$fields = $this->reflect($this);
2727
$json = json_encode($fields);
@@ -82,6 +82,6 @@ public function reflect($object = null)
8282

8383
public function __toString()
8484
{
85-
return $this->toJSON();
85+
return $this->toJson();
8686
}
8787
}

0 commit comments

Comments
 (0)