Skip to content

Commit 94ba54a

Browse files
committed
Add coding guidelines and improve type annotations
Introduces a `.github/copilot-instructions.md` file specifying project-specific coding standards, including PSR-12 adherence, PHP 8.4+ compatibility, and testing practices. Enhances type annotations and docblocks in `RO` class: - Adds detailed type hints for properties and methods. - Ensures consistency in variable initialization. - Fixes typos and clarifies documentation. Improves maintainability, readability, and alignment with best practices.
1 parent a466c4d commit 94ba54a

File tree

2 files changed

+60
-9
lines changed

2 files changed

+60
-9
lines changed

.github/copilot-instructions.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!-- Use this file to provide workspace-specific custom instructions to Copilot. For more details, visit https://code.visualstudio.com/docs/copilot/copilot-customization#_use-a-githubcopilotinstructionsmd-file -->
2+
3+
All code comments should be written in English.
4+
5+
All messages, including error messages, should be written in English.
6+
7+
All code should be written in PHP 8.4 or later.
8+
9+
All code should follow the PSR-12 coding standard.
10+
11+
When writing code, always include a docblock for functions and classes, describing their purpose, parameters, and return types.
12+
13+
When writing tests, use PHPUnit and follow the PSR-12 coding standard.
14+
15+
When writing commit messages, use the imperative mood and keep them concise.
16+
17+
When writing code comments, use complete sentences and proper grammar.
18+
19+
When writing code, always use meaningful variable names that describe their purpose.
20+
21+
When writing code, avoid using magic numbers or strings; instead, define constants for them.
22+
23+
When writing code, always handle exceptions properly and provide meaningful error messages.
24+
25+
When writing code, always include type hints for function parameters and return types.
26+
27+
We are using the i18n library for internationalization, so always use the _() functions for strings that need to be translated.
28+
29+
When writing code, always ensure that it is secure and does not expose any sensitive information.
30+
31+
When writing code, always consider performance and optimize where necessary.
32+
33+
When writing code, always ensure that it is compatible with the latest version of PHP and the libraries we are using.
34+
35+
When writing code, always ensure that it is well-tested and includes unit tests where applicable.
36+
37+
When writing code, always ensure that it is maintainable and follows best practices.
38+
39+
When create new class or update existing class, always create or update its phpunit test files.

src/AbraFlexi/RO.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class RO extends \Ease\Sand
8989
/**
9090
* Curl Handle.
9191
*/
92-
public ?\CurlHandle $curl;
92+
public ?\CurlHandle $curl = null;
9393

9494
/**
9595
* @see https://demo.flexibee.eu/devdoc/company-identifier Identifikátor firmy
@@ -132,7 +132,7 @@ class RO extends \Ease\Sand
132132
/**
133133
* Sloupeček obsahující datum vložení záznamu do shopu.
134134
*/
135-
public ?string $myCreateColumn = 'false';
135+
public ?string $myCreateColumn = null;
136136

137137
/**
138138
* Sloupeček obsahujici datum poslení modifikace záznamu do shopu.
@@ -141,8 +141,10 @@ class RO extends \Ease\Sand
141141

142142
/**
143143
* Informace o posledním HTTP requestu.
144+
*
145+
* @var null|array<string, mixed>
144146
*/
145-
public ?array $curlInfo;
147+
public null|array $curlInfo;
146148

147149
/**
148150
* Informace o poslední HTTP chybě.
@@ -181,6 +183,8 @@ class RO extends \Ease\Sand
181183

182184
/**
183185
* Last operation result data or message(s).
186+
*
187+
* @var array<mixed>|null
184188
*/
185189
public ?array $lastResult = null;
186190

@@ -212,6 +216,8 @@ class RO extends \Ease\Sand
212216
* Parmetry pro URL.
213217
*
214218
* @see https://www.abraflexi.eu/api/dokumentace/ref/urls/ Všechny podporované parametry
219+
*
220+
* @var array<string, array<string, mixed>> List of known URL parameters and their metadata
215221
*/
216222
public array $urlParamsKnown = [
217223
'add-global-version' => ['type' => 'boolean', 'description' => 'The response will contain the global version number of the current export'],
@@ -333,11 +339,15 @@ class RO extends \Ease\Sand
333339

334340
/**
335341
* List of Error500 reports sent.
342+
*
343+
* @var array<string, mixed>
336344
*/
337345
private array $reports = [];
338346

339347
/**
340-
* Columns Info for serveral evidences.
348+
* Columns Info for several evidences.
349+
*
350+
* @var array<string, mixed> Array of evidence names to their column info arrays
341351
*/
342352
private array $columnsInfo = [];
343353

@@ -521,9 +531,9 @@ public function setObjectName($objectName = null)
521531
/**
522532
* Get Current connection options for use in another object.
523533
*
524-
* @return array usable as second constructor parameter
534+
* @return array<string, int|string|null> Usable as second constructor parameter
525535
*/
526-
public function getConnectionOptions()
536+
public function getConnectionOptions(): array
527537
{
528538
$conOpts = ['url' => $this->url];
529539

@@ -548,7 +558,9 @@ public function getConnectionOptions()
548558
}
549559

550560
/**
551-
* Export current/given configutation into Environment.
561+
* Export current/given configuration into Environment.
562+
*
563+
* @param array<string, int|string|null> $opts Configuration options to export to environment variables
552564
*/
553565
public function configToEnv(array $opts = []): void
554566
{
@@ -688,7 +700,7 @@ public function setDataValue(string $columnName, $value): bool
688700
/**
689701
* Strip all non-identifier data.
690702
*
691-
* @param array $keep extra columns to be preserved
703+
* @param array<string> $keep extra columns to be preserved
692704
*
693705
* @return RO Current object state
694706
*/
@@ -1936,7 +1948,7 @@ public function getRecordID()
19361948
*/
19371949
public function getRecordCode()
19381950
{
1939-
return empty($this->getDataValue('kod')) ? null : Functions::code($this->getDataValue('kod'));
1951+
return empty($this->getDataValue('kod')) ? null : Code::ensure($this->getDataValue('kod'));
19401952
}
19411953

19421954
/**

0 commit comments

Comments
 (0)