Skip to content

Commit 387ee26

Browse files
Merge pull request #364 from opentok/php-8.1-update
chore: Drop unsupported PHP versions and rector to 8.1
2 parents 1419916 + 7eb0b3f commit 387ee26

34 files changed

+843
-1195
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
- ubuntu-latest
77
strategy:
88
matrix:
9-
php: ['8.1', '8.2', '8.3', '8.4']
9+
php: ['8.1', '8.2', '8.3', '8.4', '8.5']
1010
steps:
1111
- name: Configure Git
1212
if: ${{ matrix.os == 'windows-latest' }}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ docs/
1010
.phpdoc/
1111
phpDocumentor*
1212
.phpunit.result.cache
13-
.idea/*
13+
.idea/*
14+
var/

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"issues": "https://github.com/opentok/Opentok-PHP-SDK/issues"
2929
},
3030
"require": {
31-
"php": "^7.2|^8.0",
31+
"php": "^8.1|^8.2|^8.3|^8.4|^8.5",
3232
"ext-xml": "*",
3333
"johnstevenson/json-works": "~1.1",
3434
"firebase/php-jwt": "^6.11",
@@ -37,14 +37,14 @@
3737
"vonage/jwt": "^0.5.1"
3838
},
3939
"require-dev": {
40-
"phpunit/phpunit": "^7.4|^8.0",
40+
"phpunit/phpunit": "^8.0",
4141
"php-http/mock-client": "^1.4",
4242
"helmich/phpunit-json-assert": "^3.0.0",
4343
"squizlabs/php_codesniffer": "^3.1",
4444
"php-http/guzzle7-adapter": "^1.0",
45-
"phpstan/phpstan": "^0.12",
46-
"rector/rector": "^0.8",
47-
"phing/phing": "~2.16.0"
45+
"phpstan/phpstan": "^1.10",
46+
"phing/phing": "~2.16.0",
47+
"rector/rector": "^1.0"
4848
},
4949
"scripts": {
5050
"phpstan": "./vendor/bin/phpstan",

rector.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\Set\ValueObject\LevelSetList;
7+
use Rector\Set\ValueObject\SetList;
8+
9+
return static function (RectorConfig $rectorConfig): void {
10+
$rectorConfig->paths([
11+
__DIR__ . '/src',
12+
__DIR__ . '/examples',
13+
__DIR__ . '/sample',
14+
__DIR__ . '/tests',
15+
]);
16+
17+
// Define a clear cache directory
18+
$rectorConfig->cacheDirectory(__DIR__ . '/var/cache/rector');
19+
20+
// Here we can define what rule sets we want to apply
21+
$rectorConfig->sets([
22+
LevelSetList::UP_TO_PHP_81,
23+
SetList::CODE_QUALITY,
24+
SetList::DEAD_CODE,
25+
SetList::PRIVATIZATION,
26+
SetList::TYPE_DECLARATION,
27+
SetList::EARLY_RETURN,
28+
]);
29+
30+
// Skip certain files or directories if needed
31+
$rectorConfig->skip([
32+
__DIR__ . '/vendor',
33+
__DIR__ . '/var',
34+
__DIR__ . '/tools',
35+
]);
36+
37+
// Import names (classes, functions) automatically
38+
$rectorConfig->importNames();
39+
$rectorConfig->importShortClasses();
40+
41+
// Register file extensions
42+
$rectorConfig->fileExtensions(['php']);
43+
44+
// Parallel processing - adjust number based on your CPU cores
45+
$rectorConfig->parallel();
46+
};

rector.yaml

Lines changed: 0 additions & 5 deletions
This file was deleted.

sample/Archiving/web/index.php

Lines changed: 24 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use Slim\Views\Twig;
4+
35
$autoloader = __DIR__ . '/../vendor/autoload.php';
46
$sdkAutoloader = __DIR__ . '/../../../vendor/autoload.php';
57

@@ -23,7 +25,7 @@
2325
use OpenTok\OutputMode;
2426

2527
// PHP CLI webserver compatibility, serving static files
26-
$filename = __DIR__ . preg_replace('#(\?.*)$#', '', $_SERVER['REQUEST_URI']);
28+
$filename = __DIR__ . preg_replace('#(\?.*)$#', '', (string) $_SERVER['REQUEST_URI']);
2729
if (php_sapi_name() === 'cli-server' && is_file($filename)) {
2830
return false;
2931
}
@@ -34,109 +36,77 @@
3436
}
3537

3638
// Initialize Slim application
37-
$app = new Slim(array(
38-
'templates.path' => __DIR__ . '/../templates',
39-
'view' => new \Slim\Views\Twig(),
40-
));
39+
$app = new Slim(['templates.path' => __DIR__ . '/../templates', 'view' => new Twig()]);
4140

4241
// Intialize a cache, store it in the app container
43-
$app->container->singleton('cache', function () {
44-
return new Cache();
45-
});
42+
$app->container->singleton('cache', fn(): Cache => new Cache());
4643

4744
// Initialize OpenTok instance, store it in the app contianer
48-
$app->container->singleton('opentok', function () {
49-
return new OpenTok(getenv('API_KEY'), getenv('API_SECRET'));
50-
});
45+
$app->container->singleton('opentok', fn(): OpenTok => new OpenTok(getenv('API_KEY'), getenv('API_SECRET')));
5146
// Store the API Key in the app container
5247
$app->apiKey = getenv('API_KEY');
5348

5449
// If a sessionId has already been created, retrieve it from the cache
55-
$sessionId = $app->cache->getOrCreate('sessionId', array(), function () use ($app) {
50+
$sessionId = $app->cache->getOrCreate('sessionId', [], function () use ($app) {
5651
// If the sessionId hasn't been created, create it now and store it
57-
$session = $app->opentok->createSession(array(
58-
'mediaMode' => MediaMode::ROUTED
59-
));
52+
$session = $app->opentok->createSession(['mediaMode' => MediaMode::ROUTED]);
6053
return $session->getSessionId();
6154
});
6255

6356
// Configure routes
64-
$app->get('/', function () use ($app) {
57+
$app->get('/', function () use ($app): void {
6558
$app->render('index.html');
6659
});
6760

68-
$app->get('/host', function () use ($app, $sessionId) {
61+
$app->get('/host', function () use ($app, $sessionId): void {
6962

70-
$token = $app->opentok->generateToken($sessionId, array(
71-
'role' => Role::MODERATOR
72-
));
63+
$token = $app->opentok->generateToken($sessionId, ['role' => Role::MODERATOR]);
7364

74-
$app->render('host.html', array(
75-
'apiKey' => $app->apiKey,
76-
'sessionId' => $sessionId,
77-
'token' => $token
78-
));
65+
$app->render('host.html', ['apiKey' => $app->apiKey, 'sessionId' => $sessionId, 'token' => $token]);
7966
});
8067

81-
$app->get('/participant', function () use ($app, $sessionId) {
68+
$app->get('/participant', function () use ($app, $sessionId): void {
8269

83-
$token = $app->opentok->generateToken($sessionId, array(
84-
'role' => Role::MODERATOR
85-
));
70+
$token = $app->opentok->generateToken($sessionId, ['role' => Role::MODERATOR]);
8671

87-
$app->render('participant.html', array(
88-
'apiKey' => $app->apiKey,
89-
'sessionId' => $sessionId,
90-
'token' => $token
91-
));
72+
$app->render('participant.html', ['apiKey' => $app->apiKey, 'sessionId' => $sessionId, 'token' => $token]);
9273
});
9374

94-
$app->get('/history', function () use ($app) {
75+
$app->get('/history', function () use ($app): void {
9576
$page = intval($app->request->get('page'));
96-
if (empty($page)) {
77+
if ($page === 0) {
9778
$page = 1;
9879
}
9980

10081
$offset = ($page - 1) * 5;
10182

10283
$archives = $app->opentok->listArchives($offset, 5);
10384

104-
$toArray = function ($archive) {
105-
return $archive->toArray();
106-
};
85+
$toArray = fn($archive) => $archive->toArray();
10786

108-
$app->render('history.html', array(
109-
'archives' => array_map($toArray, $archives->getItems()),
110-
'showPrevious' => $page > 1 ? '/history?page=' . ($page - 1) : null,
111-
'showNext' => $archives->totalCount() > $offset + 5 ? '/history?page=' . ($page + 1) : null
112-
));
87+
$app->render('history.html', ['archives' => array_map($toArray, $archives->getItems()), 'showPrevious' => $page > 1 ? '/history?page=' . ($page - 1) : null, 'showNext' => $archives->totalCount() > $offset + 5 ? '/history?page=' . ($page + 1) : null]);
11388
});
11489

115-
$app->get('/download/:archiveId', function ($archiveId) use ($app) {
90+
$app->get('/download/:archiveId', function ($archiveId) use ($app): void {
11691
$archive = $app->opentok->getArchive($archiveId);
11792
$app->redirect($archive->url);
11893
});
11994

120-
$app->post('/start', function () use ($app, $sessionId) {
95+
$app->post('/start', function () use ($app, $sessionId): void {
12196

122-
$archive = $app->opentok->startArchive($sessionId, array(
123-
'name' => "PHP Archiving Sample App",
124-
'hasAudio' => ($app->request->post('hasAudio') == 'on'),
125-
'hasVideo' => ($app->request->post('hasVideo') == 'on'),
126-
'outputMode' => ($app->request->post('outputMode') == 'composed' ? OutputMode::COMPOSED : OutputMode::INDIVIDUAL)
127-
));
97+
$archive = $app->opentok->startArchive($sessionId, ['name' => "PHP Archiving Sample App", 'hasAudio' => ($app->request->post('hasAudio') == 'on'), 'hasVideo' => ($app->request->post('hasVideo') == 'on'), 'outputMode' => ($app->request->post('outputMode') == 'composed' ? OutputMode::COMPOSED : OutputMode::INDIVIDUAL)]);
12898

12999
$app->response->headers->set('Content-Type', 'application/json');
130100
echo $archive->toJson();
131101
});
132102

133-
$app->get('/stop/:archiveId', function ($archiveId) use ($app) {
103+
$app->get('/stop/:archiveId', function ($archiveId) use ($app): void {
134104
$archive = $app->opentok->stopArchive($archiveId);
135105
$app->response->headers->set('Content-Type', 'application/json');
136106
echo $archive->toJson();
137107
});
138108

139-
$app->get('/delete/:archiveId', function ($archiveId) use ($app) {
109+
$app->get('/delete/:archiveId', function ($archiveId) use ($app): void {
140110
$app->opentok->deleteArchive($archiveId);
141111
$app->redirect('/history');
142112
});

sample/HelloWorld/web/index.php

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use OpenTok\OpenTok;
2121

2222
// PHP CLI webserver compatibility, serving static files
23-
$filename = __DIR__ . preg_replace('#(\?.*)$#', '', $_SERVER['REQUEST_URI']);
23+
$filename = __DIR__ . preg_replace('#(\?.*)$#', '', (string) $_SERVER['REQUEST_URI']);
2424
if (php_sapi_name() === 'cli-server' && is_file($filename)) {
2525
return false;
2626
}
@@ -31,27 +31,21 @@
3131
}
3232

3333
// Initialize Slim application
34-
$app = new Slim(array(
35-
'templates.path' => __DIR__ . '/../templates'
36-
));
34+
$app = new Slim(['templates.path' => __DIR__ . '/../templates']);
3735

3836
// Intialize a cache, store it in the app container
39-
$app->container->singleton('cache', function () {
40-
return new Cache();
41-
});
37+
$app->container->singleton('cache', fn(): Cache => new Cache());
4238

4339
// Initialize OpenTok instance, store it in the app contianer
44-
$app->container->singleton('opentok', function () {
45-
return new OpenTok(getenv('API_KEY'), getenv('API_SECRET'));
46-
});
40+
$app->container->singleton('opentok', fn(): OpenTok => new OpenTok(getenv('API_KEY'), getenv('API_SECRET')));
4741
// Store the API Key in the app container
4842
$app->apiKey = getenv('API_KEY');
4943

5044
// Configure routes
51-
$app->get('/', function () use ($app) {
45+
$app->get('/', function () use ($app): void {
5246

5347
// If a sessionId has already been created, retrieve it from the cache
54-
$sessionId = $app->cache->getOrCreate('sessionId', array(), function () use ($app) {
48+
$sessionId = $app->cache->getOrCreate('sessionId', [], function () use ($app) {
5549
// If the sessionId hasn't been created, create it now and store it
5650
$session = $app->opentok->createSession();
5751
return $session->getSessionId();
@@ -60,11 +54,7 @@
6054
// Generate a fresh token for this client
6155
$token = $app->opentok->generateToken($sessionId);
6256

63-
$app->render('helloworld.php', array(
64-
'apiKey' => $app->apiKey,
65-
'sessionId' => $sessionId,
66-
'token' => $token
67-
));
57+
$app->render('helloworld.php', ['apiKey' => $app->apiKey, 'sessionId' => $sessionId, 'token' => $token]);
6858
});
6959

7060
$app->run();

sample/SipCall/web/index.php

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use OpenTok\MediaMode;
2222

2323
// PHP CLI webserver compatibility, serving static files
24-
$filename = __DIR__ . preg_replace('#(\?.*)$#', '', $_SERVER['REQUEST_URI']);
24+
$filename = __DIR__ . preg_replace('#(\?.*)$#', '', (string) $_SERVER['REQUEST_URI']);
2525
if (php_sapi_name() === 'cli-server' && is_file($filename)) {
2626
return false;
2727
}
@@ -32,62 +32,43 @@
3232
}
3333

3434
// Initialize Slim application
35-
$app = new Slim(array(
36-
'templates.path' => __DIR__ . '/../templates'
37-
));
35+
$app = new Slim(['templates.path' => __DIR__ . '/../templates']);
3836

3937
// Intialize a cache, store it in the app container
40-
$app->container->singleton('cache', function () {
41-
return new Cache();
42-
});
38+
$app->container->singleton('cache', fn(): Cache => new Cache());
4339

4440
// Initialize OpenTok instance, store it in the app contianer
45-
$app->container->singleton('opentok', function () {
46-
return new OpenTok(getenv('API_KEY'), getenv('API_SECRET'));
47-
});
41+
$app->container->singleton('opentok', fn(): OpenTok => new OpenTok(getenv('API_KEY'), getenv('API_SECRET')));
4842
// Store the API Key in the app container
4943
$app->apiKey = getenv('API_KEY');
5044

51-
$app->sip = array(
52-
'uri' => getenv('SIP_URI'),
53-
'username' => getenv('SIP_USERNAME'),
54-
'password' => getenv('SIP_PASSWORD'),
55-
'secure' => (getenv('SIP_SECURE') === 'true'),
56-
'from' => getenv('SIP_FROM'),
57-
);
45+
$app->sip = ['uri' => getenv('SIP_URI'), 'username' => getenv('SIP_USERNAME'), 'password' => getenv('SIP_PASSWORD'), 'secure' => (getenv('SIP_SECURE') === 'true'), 'from' => getenv('SIP_FROM')];
5846

5947
// Configure routes
60-
$app->get('/', function () use ($app) {
48+
$app->get('/', function () use ($app): void {
6149
// If a sessionId has already been created, retrieve it from the cache
62-
$sessionId = $app->cache->getOrCreate('sessionId', array(), function () use ($app) {
50+
$sessionId = $app->cache->getOrCreate('sessionId', [], function () use ($app) {
6351
// If the sessionId hasn't been created, create it now and store it
64-
$session = $app->opentok->createSession(array('mediaMode' => MediaMode::ROUTED));
52+
$session = $app->opentok->createSession(['mediaMode' => MediaMode::ROUTED]);
6553
return $session->getSessionId();
6654
});
6755

6856
// Generate a fresh token for this client
69-
$token = $app->opentok->generateToken($sessionId, array('role' => 'moderator'));
57+
$token = $app->opentok->generateToken($sessionId, ['role' => 'moderator']);
7058

71-
$app->render('index.php', array(
72-
'apiKey' => $app->apiKey,
73-
'sessionId' => $sessionId,
74-
'token' => $token
75-
));
59+
$app->render('index.php', ['apiKey' => $app->apiKey, 'sessionId' => $sessionId, 'token' => $token]);
7660
});
7761

78-
$app->post('/sip/start', function () use ($app) {
62+
$app->post('/sip/start', function () use ($app): void {
7963
$sessionId = $app->request->post('sessionId');
8064

8165
// generate a token
82-
$token = $app->opentok->generateToken($sessionId, array('data' => 'sip=true'));
66+
$token = $app->opentok->generateToken($sessionId, ['data' => 'sip=true']);
8367

8468
// create the options parameter
85-
$options = array(
86-
'secure' => $app->sip['secure'],
87-
'from' => $app->sip['from'],
88-
);
69+
$options = ['secure' => $app->sip['secure'], 'from' => $app->sip['from']];
8970
if ($app->sip['username'] !== false) {
90-
$options['auth'] = array('username' => $app->sip['username'], 'password' => $app->sip['password']);
71+
$options['auth'] = ['username' => $app->sip['username'], 'password' => $app->sip['password']];
9172
}
9273

9374
// make the sip call

0 commit comments

Comments
 (0)