Skip to content

Commit fe0523f

Browse files
committed
Added linter, set linting standard to PSR12
1 parent 73675fb commit fe0523f

32 files changed

Lines changed: 491 additions & 427 deletions

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ See detailed [API documentation](https://typesense.org/api).
1818

1919
## Compatibility
2020

21-
| Typesense Server | typesense-ruby |
21+
| Typesense Server | typesense-php |
2222
|------------------|----------------|
2323
| \>= v0.15.0 | \>= v2.0.4 |
2424
| \>= v0.12.0 | \>= v2.0.0 |
@@ -28,6 +28,20 @@ See detailed [API documentation](https://typesense.org/api).
2828

2929
Bug reports and pull requests are welcome on GitHub at [https://github.com/typesense/typesense-php].
3030

31+
## Development
32+
33+
Run linter:
34+
35+
```shell script
36+
composer run-script lint:fix
37+
```
38+
39+
Run Typesense Server:
40+
41+
```shell script
42+
composer run-script typesenseServer
43+
```
44+
3145
## Credits
3246

3347
This client was originally developed by [Abdullah Al-Faqeir](https://github.org/abdullahfaqeir) and was

composer.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,15 @@
3434
"guzzlehttp/guzzle": "^7.0",
3535
"ext-json": "*"
3636
},
37+
"require-dev": {
38+
"squizlabs/php_codesniffer": "3.*"
39+
},
3740
"scripts": {
3841
"typesenseServer": [
3942
"Composer\\Config::disableProcessTimeout",
4043
"docker run -i -p 8108:8108 -v/tmp/typesense-server-data-1c/:/data typesense/typesense:0.15.0 --data-dir /data --api-key=xyz --listen-port 8108 --enable-cors"
41-
]
44+
],
45+
"lint": "phpcs -v",
46+
"lint:fix": "phpcbf"
4247
}
4348
}

examples/alias_operations.php

Lines changed: 87 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
<?php /** @noinspection ForgottenDebugOutputInspection */
1+
<?php
2+
3+
/** @noinspection ForgottenDebugOutputInspection */
24

35
include '../vendor/autoload.php';
46

5-
use \Typesense\Client;
7+
use Typesense\Client;
68

79
try {
810
$client = new Client(
9-
[
10-
'api_key' => 'xyz',
11-
'nodes' => [
12-
[
13-
'host' => 'localhost',
14-
'port' => '8108',
15-
'protocol' => 'http',
16-
],
17-
],
18-
'connection_timeout_seconds' => 2,
19-
]
11+
[
12+
'api_key' => 'xyz',
13+
'nodes' => [
14+
[
15+
'host' => 'localhost',
16+
'port' => '8108',
17+
'protocol' => 'http',
18+
],
19+
],
20+
'connection_timeout_seconds' => 2,
21+
]
2022
);
2123
echo '<pre>';
2224
try {
@@ -31,94 +33,94 @@
3133
}
3234
echo "--------Create Collection-------\n";
3335
print_r(
34-
$client->collections->create(
35-
[
36-
'name' => 'books_january',
37-
'fields' => [
38-
[
39-
'name' => 'title',
40-
'type' => 'string',
41-
],
42-
[
43-
'name' => 'authors',
44-
'type' => 'string[]',
45-
],
46-
[
47-
'name' => 'authors_facet',
48-
'type' => 'string[]',
49-
'facet' => true,
50-
],
51-
[
52-
'name' => 'publication_year',
53-
'type' => 'int32',
54-
],
55-
[
56-
'name' => 'publication_year_facet',
57-
'type' => 'string',
58-
'facet' => true,
59-
],
36+
$client->collections->create(
6037
[
61-
'name' => 'ratings_count',
62-
'type' => 'int32',
63-
],
64-
[
65-
'name' => 'average_rating',
66-
'type' => 'float',
67-
],
68-
[
69-
'name' => 'image_url',
70-
'type' => 'string',
71-
],
72-
],
73-
'default_sorting_field' => 'ratings_count',
74-
]
75-
)
38+
'name' => 'books_january',
39+
'fields' => [
40+
[
41+
'name' => 'title',
42+
'type' => 'string',
43+
],
44+
[
45+
'name' => 'authors',
46+
'type' => 'string[]',
47+
],
48+
[
49+
'name' => 'authors_facet',
50+
'type' => 'string[]',
51+
'facet' => true,
52+
],
53+
[
54+
'name' => 'publication_year',
55+
'type' => 'int32',
56+
],
57+
[
58+
'name' => 'publication_year_facet',
59+
'type' => 'string',
60+
'facet' => true,
61+
],
62+
[
63+
'name' => 'ratings_count',
64+
'type' => 'int32',
65+
],
66+
[
67+
'name' => 'average_rating',
68+
'type' => 'float',
69+
],
70+
[
71+
'name' => 'image_url',
72+
'type' => 'string',
73+
],
74+
],
75+
'default_sorting_field' => 'ratings_count',
76+
]
77+
)
7678
);
7779
echo "--------Create Collection-------\n";
7880
echo "\n";
7981
echo "--------Create Collection Alias-------\n";
8082
print_r(
81-
$client->aliases->upsert(
82-
'books',
83-
[
84-
'collection_name' => 'books_january',
85-
]
86-
)
83+
$client->aliases->upsert(
84+
'books',
85+
[
86+
'collection_name' => 'books_january',
87+
]
88+
)
8789
);
8890
echo "--------Create Collection Alias-------\n";
8991
echo "\n";
9092
echo "--------Create Document on Alias-------\n";
9193
print_r(
92-
$client->collections['books']->documents->create(
93-
[
94-
'id' => '1',
95-
'original_publication_year' => 2008,
96-
'authors' => [
97-
'Suzanne Collins',
98-
],
99-
'average_rating' => 4.34,
100-
'publication_year' => 2008,
101-
'publication_year_facet' => '2008',
102-
'authors_facet' => [
103-
'Suzanne Collins',
104-
],
105-
'title' => 'The Hunger Games',
106-
'image_url' => 'https://images.gr-assets.com/books/1447303603m/2767052.jpg',
107-
'ratings_count' => 4780653,
108-
]
109-
)
94+
$client->collections['books']->documents->create(
95+
[
96+
'id' => '1',
97+
'original_publication_year' => 2008,
98+
'authors' => [
99+
'Suzanne Collins',
100+
],
101+
'average_rating' => 4.34,
102+
'publication_year' => 2008,
103+
'publication_year_facet' => '2008',
104+
'authors_facet' => [
105+
'Suzanne Collins',
106+
],
107+
'title' => 'The Hunger Games',
108+
'image_url' => 'https://images.gr-assets.com/books/1447303603m/2767052.jpg',
109+
'ratings_count' => 4780653,
110+
]
111+
)
110112
);
111113
echo "--------Create Document on Alias-------\n";
112114
echo "\n";
113115
echo "--------Search Document on Alias-------\n";
114116
print_r(
115-
$client->collections['books']->documents->search(
116-
[
117-
'q' => 'hunger',
118-
'query_by' => 'title',
119-
'sort_by' => 'ratings_count:desc',
120-
]
121-
)
117+
$client->collections['books']->documents->search(
118+
[
119+
'q' => 'hunger',
120+
'query_by' => 'title',
121+
'sort_by' => 'ratings_count:desc',
122+
]
123+
)
122124
);
123125
echo "--------Search Document on Alias-------\n";
124126
echo "\n";

0 commit comments

Comments
 (0)