Skip to content

Commit 6b8195e

Browse files
authored
Merge pull request #96 from microsoftgraph/dev
Release 2.0.0-RC7
2 parents bb61bcd + eb0d71b commit 6b8195e

34 files changed

+569
-277
lines changed

.github/workflows/pr-validation.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ defaults:
1818
jobs:
1919
validate-pull-request:
2020
runs-on: ubuntu-latest
21+
strategy:
22+
matrix:
23+
php-versions: ['7.4', '8.0', '8.1', '8.2']
2124
steps:
22-
- uses: actions/checkout@v3.3.0
25+
- uses: actions/checkout@v3.5.2
2326
with:
2427
submodules: 'true'
2528
- name: Setup PHP and Xdebug for Code Coverage report
2629
uses: shivammathur/setup-php@v2
2730
with:
28-
php-version: '7.4'
31+
php-version: ${{ matrix.php-versions }}
2932
coverage: xdebug
3033
- name: Validate composer file
3134
run: |
@@ -34,8 +37,15 @@ jobs:
3437
run: |
3538
composer install
3639
- name: Run tests
37-
run : |
38-
vendor/bin/phpunit --coverage-text
40+
run: ./vendor/bin/phpunit --coverage-clover=coverage.xml
41+
- name: Fix code coverage paths
42+
run: sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' coverage.xml
43+
- name: SonarCloud Scan
44+
if: ${{ matrix.php-versions == '8.0' }}
45+
uses: SonarSource/sonarcloud-github-action@master
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
3949
- name: Run static analysis
4050
run: |
4151
vendor/bin/phpstan analyse --memory-limit=500M --error-format=github

.github/workflows/tag-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
create-tag:
1919
runs-on: ubuntu-latest
2020
steps:
21-
- uses: actions/checkout@v3.3.0
21+
- uses: actions/checkout@v3.5.2
2222

2323
- name: Get SDK version and set environment variable
2424
run: |

.github/workflows/update-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
run-php-documentor:
1616
runs-on: ubuntu-latest
1717
steps:
18-
- uses: actions/checkout@v3.3.0
18+
- uses: actions/checkout@v3.5.2
1919
with:
2020
ref: ${{ github.ref }}
2121

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Get started with the Microsoft Graph Core SDK for PHP
22

33
[![Latest Stable Version](https://poser.pugx.org/microsoft/microsoft-graph-core/version)](https://packagist.org/packages/microsoft/microsoft-graph-core)
4+
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=microsoftgraph_msgraph-sdk-php-core&metric=coverage)](https://sonarcloud.io/dashboard?id=microsoftgraph_msgraph-sdk-php-core)
45

56
## Install the Core Library
67
To install the `microsoft-graph-core` library with Composer, either run `composer require microsoft/microsoft-graph-core`, or edit your `composer.json` file:
78
```
89
{
910
"require": {
10-
"microsoft/microsoft-graph-core": "^2.0.0-RC4"
11+
"microsoft/microsoft-graph-core": "^2.0.0-RC7"
1112
}
1213
}
1314
```

composer.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313
],
1414
"require": {
1515
"php": "^8.0 || ^7.4",
16-
"microsoft/kiota-authentication-phpleague": "^0.4.0",
17-
"microsoft/kiota-http-guzzle": "^0.4.0",
18-
"microsoft/kiota-serialization-json": "^0.3.0",
19-
"microsoft/kiota-serialization-text": "^0.3.0",
20-
"microsoft/kiota-abstractions": "^0.4.0",
16+
"microsoft/kiota-authentication-phpleague": "^0.6.0",
17+
"microsoft/kiota-http-guzzle": "^0.6.0",
18+
"microsoft/kiota-serialization-json": "^0.4.0",
19+
"microsoft/kiota-serialization-text": "^0.5.0",
2120
"php-http/httplug": "^2.2",
2221
"php-http/guzzle7-adapter": "^1.0",
2322
"ext-json": "*"

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 3
2+
level: 9
33
polluteScopeWithAlwaysIterableForeach: false
44
polluteScopeWithLoopInitialAssignments: false
55
paths:

sonar-project.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sonar.projectKey=microsoftgraph_msgraph-sdk-php-core
2+
sonar.organization=microsoftgraph2
3+
sonar.php.coverage.reportPaths=coverage.xml
4+
sonar.sources=src/
5+
sonar.tests=tests/
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Copyright (c) Microsoft Corporation. All Rights Reserved.
4+
* Licensed under the MIT License. See License in the project root
5+
* for license information.
6+
*/
7+
8+
9+
namespace Microsoft\Graph\Core\Authentication;
10+
11+
12+
use Microsoft\Kiota\Authentication\Oauth\TokenRequestContext;
13+
use Microsoft\Kiota\Authentication\PhpLeagueAccessTokenProvider;
14+
15+
/**
16+
* Class GraphPhpLeagueAccessTokenProvider
17+
*
18+
* Fetches an access token using the PHP League OAuth 2.0 client library while setting default Graph allowed hosts
19+
*
20+
* @package Microsoft\Graph\Core\Authentication
21+
* @copyright 2023 Microsoft Corporation
22+
* @license https://opensource.org/licenses/MIT MIT License
23+
* @link https://developer.microsoft.com/graph
24+
*/
25+
class GraphPhpLeagueAccessTokenProvider extends PhpLeagueAccessTokenProvider
26+
{
27+
/**
28+
* @param TokenRequestContext $tokenRequestContext
29+
* @param array<string> $scopes if left empty, it's set to ["https://[graph national cloud host]/.default"] scope
30+
*/
31+
public function __construct(TokenRequestContext $tokenRequestContext, array $scopes = [])
32+
{
33+
$allowedHosts = ["graph.microsoft.com", "graph.microsoft.us", "dod-graph.microsoft.us", "graph.microsoft.de",
34+
"microsoftgraph.chinacloudapi.cn", "canary.graph.microsoft.com"];
35+
parent::__construct($tokenRequestContext, $scopes, $allowedHosts);
36+
}
37+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Copyright (c) Microsoft Corporation. All Rights Reserved.
4+
* Licensed under the MIT License. See License in the project root
5+
* for license information.
6+
*/
7+
8+
9+
namespace Microsoft\Graph\Core\Authentication;
10+
11+
use Microsoft\Kiota\Abstractions\Authentication\BaseBearerTokenAuthenticationProvider;
12+
use Microsoft\Kiota\Authentication\Oauth\TokenRequestContext;
13+
14+
/**
15+
* Class GraphPhpLeagueAuthenticationProvider
16+
* @package Microsoft\Graph\Core\Authentication
17+
* @copyright 2023 Microsoft Corporation
18+
* @license https://opensource.org/licenses/MIT MIT License
19+
* @link https://developer.microsoft.com/graph
20+
*/
21+
class GraphPhpLeagueAuthenticationProvider extends BaseBearerTokenAuthenticationProvider
22+
{
23+
/**
24+
* @param TokenRequestContext $tokenRequestContext
25+
* @param array<string> $scopes defaults to ["https://[graph national cloud host]/.default"] scope
26+
*/
27+
public function __construct(TokenRequestContext $tokenRequestContext, array $scopes = [])
28+
{
29+
$accessTokenProvider = new GraphPhpLeagueAccessTokenProvider($tokenRequestContext, $scopes);
30+
parent::__construct($accessTokenProvider);
31+
}
32+
}

src/BaseGraphRequestAdapter.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@
2828
class BaseGraphRequestAdapter extends GuzzleRequestAdapter
2929
{
3030
/**
31+
* @param GraphTelemetryOption $telemetryOption
3132
* @param AuthenticationProvider|null $authenticationProvider
32-
* @param GraphTelemetryOption|null $telemetryOption
3333
* @param ParseNodeFactory|null $parseNodeFactory
3434
* @param SerializationWriterFactory|null $serializationWriterFactory
3535
* @param Client|null $guzzleClient
3636
*/
37-
public function __construct(?AuthenticationProvider $authenticationProvider = null, ?GraphTelemetryOption $telemetryOption = null, ?ParseNodeFactory $parseNodeFactory = null, ?SerializationWriterFactory $serializationWriterFactory = null, ?Client $guzzleClient = null)
37+
public function __construct(GraphTelemetryOption $telemetryOption,
38+
?AuthenticationProvider $authenticationProvider = null,
39+
?ParseNodeFactory $parseNodeFactory = null,
40+
?SerializationWriterFactory $serializationWriterFactory = null,
41+
?Client $guzzleClient = null)
3842
{
3943
$authenticationProvider = ($authenticationProvider) ?? new AnonymousAuthenticationProvider();
4044
$guzzleClient = ($guzzleClient) ?? GraphClientFactory::setTelemetryOption($telemetryOption)::create();

src/GraphClientFactory.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ final class GraphClientFactory extends KiotaClientFactory
4646
/**
4747
* @var string Graph API host to use as base URL and for authentication
4848
*/
49-
private static $nationalCloud = NationalCloud::GLOBAL;
49+
private static string $nationalCloud = NationalCloud::GLOBAL;
5050

5151
/**
5252
* @var GraphClientFactory|null Store singleton instance of the GraphClientFactory
5353
*/
54-
private static $instance = null;
54+
private static ?GraphClientFactory $instance = null;
5555

5656
/**
5757
* @var GraphTelemetryOption|null telemetry config
5858
*/
59-
private static $graphTelemetryOption = null;
59+
private static ?GraphTelemetryOption $graphTelemetryOption = null;
6060

6161
/**
6262
* GraphClientFactory constructor.
@@ -105,7 +105,7 @@ public static function setTelemetryOption(GraphTelemetryOption $telemetryOption)
105105
/**
106106
* Create Guzzle client configured for Graph
107107
*
108-
* @param array $guzzleConfig
108+
* @param array<string, mixed> $guzzleConfig
109109
* @return Client
110110
*/
111111
public static function createWithConfig(array $guzzleConfig): Client
@@ -141,7 +141,7 @@ public static function createWithMiddleware(HandlerStack $handlerStack): Client
141141
*/
142142
public static function createAdapter(): HttpClientInterface {
143143
return new class(self::create()) implements HttpClientInterface {
144-
private $clientAdapter;
144+
private GuzzleAdapter $clientAdapter;
145145

146146
public function __construct(Client $guzzleClient) {
147147
$this->clientAdapter = new GuzzleAdapter($guzzleClient);
@@ -160,10 +160,10 @@ public function sendAsyncRequest(RequestInterface $request): Promise {
160160
/**
161161
* Return default handler stack for Graph
162162
*
163-
* @param null $handler final handler
163+
* @param callable|null $handler final handler
164164
* @return HandlerStack
165165
*/
166-
public static function getDefaultHandlerStack($handler = null): HandlerStack
166+
public static function getDefaultHandlerStack(callable $handler = null): HandlerStack
167167
{
168168
$handler = ($handler) ?: Utils::chooseHandler();
169169
$handlerStack = new HandlerStack($handler);
@@ -176,7 +176,7 @@ public static function getDefaultHandlerStack($handler = null): HandlerStack
176176
/**
177177
* Returns Graph-specific config for Guzzle
178178
*
179-
* @return array
179+
* @return array<string, mixed>
180180
*/
181181
private static function getDefaultConfig(): array {
182182
$config = [
@@ -189,9 +189,12 @@ private static function getDefaultConfig(): array {
189189
"base_uri" => self::$nationalCloud,
190190
'handler' => self::getDefaultHandlerStack()
191191
];
192-
if (extension_loaded('curl') && defined('CURL_VERSION_HTTP2') && curl_version()["features"] & CURL_VERSION_HTTP2 !== 0) {
193-
// Enable HTTP/2 if curl extension exists and supports it
194-
$config['version'] = '2';
192+
if (extension_loaded('curl') && defined('CURL_VERSION_HTTP2')) {
193+
$curlVersion = curl_version();
194+
if ($curlVersion && ($curlVersion["features"] & CURL_VERSION_HTTP2) == CURL_VERSION_HTTP2) {
195+
// Enable HTTP/2 if curl extension exists and supports it
196+
$config['version'] = '2';
197+
}
195198
}
196199
return $config;
197200
}

src/GraphConstants.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class GraphConstants
2525
const REST_ENDPOINT = "https://graph.microsoft.com/";
2626

2727
// Define HTTP request constants
28-
const SDK_VERSION = "2.0.0-RC4";
28+
const SDK_VERSION = "2.0.0-RC7";
2929

3030
// Define error constants
3131
const MAX_PAGE_SIZE = 999;

src/Middleware/FeatureFlagTrait.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,19 @@
99
namespace Microsoft\Graph\Core\Middleware;
1010

1111
use Microsoft\Graph\Core\Middleware\Option\GraphTelemetryOption;
12+
use Microsoft\Kiota\Abstractions\RequestOption;
1213

1314
/**
1415
* Adds feature flag to Guzzle options
1516
*/
1617
trait FeatureFlagTrait
1718
{
19+
20+
/**
21+
* @param int $featureFlag
22+
* @param array<string, RequestOption> $options
23+
* @return void
24+
*/
1825
function setFeatureFlag(int $featureFlag, array &$options): void {
1926
if (!array_key_exists(GraphTelemetryOption::class, $options)) {
2027
$telemetry = new GraphTelemetryOption();

src/Middleware/GraphCompressionHandler.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212
use GuzzleHttp\Promise\PromiseInterface;
13+
use Microsoft\Kiota\Abstractions\RequestOption;
1314
use Microsoft\Kiota\Http\Middleware\CompressionHandler;
1415
use Psr\Http\Message\RequestInterface;
1516

@@ -26,6 +27,11 @@ class GraphCompressionHandler extends CompressionHandler
2627

2728
const FEATURE_FLAG = 0x00000040;
2829

30+
/**
31+
* @param RequestInterface $request
32+
* @param array<string, RequestOption> $options
33+
* @return PromiseInterface
34+
*/
2935
public function __invoke(RequestInterface $request, array $options): PromiseInterface
3036
{
3137
$this->setFeatureFlag(self::FEATURE_FLAG, $options);

src/Middleware/GraphRetryHandler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212
use GuzzleHttp\Promise\PromiseInterface;
13+
use Microsoft\Kiota\Abstractions\RequestOption;
1314
use Microsoft\Kiota\Http\Middleware\RetryHandler;
1415
use Psr\Http\Message\RequestInterface;
1516

@@ -28,7 +29,7 @@ class GraphRetryHandler extends RetryHandler
2829

2930
/**
3031
* @param RequestInterface $request
31-
* @param array $options
32+
* @param array<string, RequestOption> $options
3233
* @return PromiseInterface
3334
*/
3435
public function __invoke(RequestInterface $request, array $options): PromiseInterface

src/Middleware/GraphTelemetryHandler.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
class GraphTelemetryHandler extends TelemetryHandler
2727
{
28-
private $graphTelemetryOption;
28+
private GraphTelemetryOption $graphTelemetryOption;
2929

3030
/**
3131
* Create new instance
@@ -43,15 +43,16 @@ public function __construct(callable $nextHandler, ?GraphTelemetryOption $graphT
4343
* Handles the request
4444
*
4545
* @param RequestInterface $request
46-
* @param array $options
46+
* @param array<string, mixed> $options
4747
* @return PromiseInterface
4848
*/
4949
public function __invoke(RequestInterface $request, array $options): PromiseInterface
5050
{
5151
// Merge custom request-level options with initial telemetry options
5252
if (array_key_exists(GraphTelemetryOption::class, $options)) {
5353
$graphTelemetryOption = $options[GraphTelemetryOption::class];
54-
if (is_a($graphTelemetryOption, GraphTelemetryOption::class)) {
54+
if (is_object($graphTelemetryOption) && is_a($graphTelemetryOption, GraphTelemetryOption::class)) {
55+
// @phpstan-ignore-next-line
5556
$this->graphTelemetryOption->override($options[GraphTelemetryOption::class]);
5657
unset($options[GraphTelemetryOption::class]);
5758
}

src/Middleware/Option/GraphTelemetryOption.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class GraphTelemetryOption extends TelemetryOption
3737
* @param string $apiVersion
3838
* @param string $serviceLibraryVersion
3939
*/
40-
public function __construct(string $apiVersion = '', string $serviceLibraryVersion = '')
40+
public function __construct(string $apiVersion = GraphConstants::V1_API_VERSION, string $serviceLibraryVersion = '')
4141
{
4242
$this->setApiVersion($apiVersion);
4343
$this->serviceLibraryVersion = $serviceLibraryVersion;

src/Models/LargeFileUploadCreateSessionBody.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function __construct() {
2323
* @inheritDoc
2424
*/
2525
public function getAdditionalData(): ?array {
26+
/** @phpstan-ignore-next-line */
2627
return $this->backingStore->get('additionalData');
2728
}
2829

0 commit comments

Comments
 (0)