Skip to content
This repository has been archived by the owner on May 25, 2021. It is now read-only.

Commit

Permalink
Merge pull request #16 from nenadstojanovikj/add-types
Browse files Browse the repository at this point in the history
Add types
  • Loading branch information
Nenad Stojanovikj authored Apr 1, 2019
2 parents 4cea3aa + 7cf5084 commit 43eeb34
Show file tree
Hide file tree
Showing 59 changed files with 319 additions and 426 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ unit-config: &unit-config

- run:
name: PHP Code Style
command: vendor/bin/phpcs --standard=./phpcs-ruleset.xml
command: vendor/bin/phpcs --standard=./phpcs.xml

- run:
name: PHP unit tests
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ You can check your code against these rules by running PHPCS with the proper
ruleset, like this:

```sh
$ vendor/bin/phpcs --standard=phpcs-ruleset
$ vendor/bin/phpcs --standard=phpcs.xml
```

Coding style checks are run along with the other test suites.
Coding style checks are run along with the other test suites.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"ext-opencensus": "< 0.1.0"
},
"suggest": {
"ext-json": "For using LoggerExporter",
"opencensus/opencensus-exporter-jaeger": "Export data to Jaeger",
"opencensus/opencensus-exporter-stackdriver": "Export data to Stackdriver",
"opencensus/opencensus-exporter-zipkin": "Export data to Zipkin",
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion scripts/run_local_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ DIRNAME=$(dirname $0)
$DIRNAME/../vendor/bin/phpunit

# Run code style tests
$DIRNAME/../vendor/bin/phpcs --standard=$DIRNAME/../phpcs-ruleset.xml -p
$DIRNAME/../vendor/bin/phpcs --standard=$DIRNAME/../phpcs.xml -p
16 changes: 8 additions & 8 deletions src/Core/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct($initialValues = [])
* @param mixed $value
* @return Context
*/
public function withValue($key, $value)
public function withValue($key, $value): Context
{
$copy = $this->values;
$copy[$key] = $value;
Expand All @@ -76,7 +76,7 @@ public function withValue($key, $value)
* @param array $data
* @return Context
*/
public function withValues($data)
public function withValues($data): Context
{
$copy = $this->values;
foreach ($data as $key => $value) {
Expand Down Expand Up @@ -105,7 +105,7 @@ public function value($key, $default = null)
*
* @return array
*/
public function values()
public function values(): array
{
return $this->values;
}
Expand All @@ -116,7 +116,7 @@ public function values()
*
* @return Context
*/
public function attach()
public function attach(): Context
{
$current = self::current();
self::$current = $this;
Expand All @@ -129,7 +129,7 @@ public function attach()
*
* @param Context $toAttach
*/
public function detach(Context $toAttach)
public function detach(Context $toAttach): void
{
if (self::current() !== $this) {
trigger_error('Unexpected context to detach.', E_USER_WARNING);
Expand All @@ -144,7 +144,7 @@ public function detach(Context $toAttach)
*
* @return Context
*/
public static function current()
public static function current(): Context
{
if (!self::$current) {
self::$current = self::background();
Expand All @@ -158,7 +158,7 @@ public static function current()
*
* @return Context
*/
public static function background()
public static function background(): Context
{
return new Context();
}
Expand All @@ -169,7 +169,7 @@ public static function background()
*
* @internal
*/
public static function reset()
public static function reset(): void
{
self::$current = null;
}
Expand Down
12 changes: 6 additions & 6 deletions src/Core/DaemonClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public static function init(array $options = []): DaemonClient
return self::$instance = new DaemonClient($sock, $maxSendTime);
}

public static function createMeasure(Measure $measure): bool
public function createMeasure(Measure $measure): bool
{
$msg = '';
switch (true) {
Expand All @@ -206,7 +206,7 @@ public static function createMeasure(Measure $measure): bool
return self::$instance->send(self::MSG_MEASURE_CREATE, $msg);
}

public static function setReportingPeriod(float $interval): bool
public function setReportingPeriod(float $interval): bool
{
if ($interval < 1.0) {
return false;
Expand All @@ -215,7 +215,7 @@ public static function setReportingPeriod(float $interval): bool
return self::$instance->send(self::MSG_VIEW_REPORTING_PERIOD, $msg);
}

public static function registerView(View ...$views): bool
public function registerView(View ...$views): bool
{
// bail out if we don't have views
if (count($views) === 0) {
Expand Down Expand Up @@ -247,7 +247,7 @@ public static function registerView(View ...$views): bool
return self::$instance->send(self::MSG_VIEW_REGISTER, $msg);
}

public static function unregisterView(View ...$views): bool
public function unregisterView(View ...$views): bool
{
// bail out if we don't have views
if (count($views) === 0) {
Expand All @@ -262,7 +262,7 @@ public static function unregisterView(View ...$views): bool
return self::$instance->send(self::MSG_VIEW_UNREGISTER, $msg);
}

public static function recordStats(TagContext $tagContext, array $attachments, Measurement ...$ms): bool
public function recordStats(TagContext $tagContext, array $attachments, Measurement ...$ms): bool
{
// bail out if we don't have measurements
if (count($ms) === 0) {
Expand Down Expand Up @@ -298,7 +298,7 @@ public static function recordStats(TagContext $tagContext, array $attachments, M
return self::$instance->send(self::MSG_STATS_RECORD, $msg);
}

public function export(array $spans)
public function export(array $spans): bool
{
$spanData = json_encode(array_map(function (SpanData $span) {
return [
Expand Down
10 changes: 5 additions & 5 deletions src/Stats/Exporter/ExporterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,31 @@ interface ExporterInterface
* @param Measure $measure The measure to register.
* @return bool Returns true on successful send operation.
*/
public static function createMeasure(Measure $measure): bool;
public function createMeasure(Measure $measure): bool;

/**
* Adjust the stats reporting period of the Daemom.
*
* @param float $interval Reporting interval of the daemon in seconds.
* @return bool Returns true on successful send operation.
*/
public static function setReportingPeriod(float $interval): bool;
public function setReportingPeriod(float $interval): bool;

/**
* Register views.
*
* @param View ...$views One or more Views to register.
* @return bool Returns true on successful send operation.
*/
public static function registerView(View ...$views): bool;
public function registerView(View ...$views): bool;

/**
* Unregister views.
*
* @param View ...$views Views to unregister.
* @return bool Returns true on successful send operation.
*/
public static function unregisterView(View ...$views): bool;
public function unregisterView(View ...$views): bool;

/**
* Record the provided Measurements, Attachments and Tags.
Expand All @@ -67,5 +67,5 @@ public static function unregisterView(View ...$views): bool;
* @param Measurement ...$ms One or more measurements to record.
* @return bool Returns true on successful send operation.
*/
public static function recordStats(TagContext $tagContext, array $attachments, Measurement ...$ms): bool;
public function recordStats(TagContext $tagContext, array $attachments, Measurement ...$ms): bool;
}
10 changes: 5 additions & 5 deletions src/Stats/Exporter/NoopExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,27 @@

class NoopExporter implements ExporterInterface
{
public static function createMeasure(Measure $measure): bool
public function createMeasure(Measure $measure): bool
{
return true;
}

public static function setReportingPeriod(float $interval): bool
public function setReportingPeriod(float $interval): bool
{
return true;
}

public static function registerView(View ...$views): bool
public function registerView(View ...$views): bool
{
return true;
}

public static function unregisterView(View ...$views): bool
public function unregisterView(View ...$views): bool
{
return true;
}

public static function recordStats(TagContext $tags, array $attachments, Measurement ...$ms): bool
public function recordStats(TagContext $tags, array $attachments, Measurement ...$ms): bool
{
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Stats/FloatMeasure.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ final protected function __construct(string $name, string $description, string $
* Constructs a new FloatMeasure.
*
* @param string $name Unique name of the Measure.
* @param string $description Human readable discription of the Measure.
* @param string $description Human readable description of the Measure.
* @param string $unit Unit of the Measure. See
* <a href="http://unitsofmeasure.org/ucum.html">Unified Code for Units of Measure</a>
* @return FloatMeasure
* @throws \Exception Throws on invalid measure name.
*/
final public static function create(
string $name,
string $description = "",
string $description = '',
string $unit = Measure::DIMENSIONLESS
): FloatMeasure {
return self::registerMeasureHandle($name, $description, $unit);
Expand All @@ -74,7 +74,7 @@ final public function m(float $value): Measurement
* @param float $value The value of this Measurement.
*/

public function __construct(Measure &$measure, float $value)
public function __construct(Measure $measure, float $value)
{
parent::__construct($measure, $value);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Stats/IntMeasure.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ final protected function __construct(string $name, string $description, string $
* Constructs a new IntMeasure.
*
* @param string $name Unique name of the Measure.
* @param string $description Human readable discription of the Measure.
* @param string $description Human readable description of the Measure.
* @param string $unit Unit of the Measure. See
* <a href="http://unitsofmeasure.org/ucum.html">Unified Code for Units of Measure</a>
* @return IntMeasure
* @throws \Exception Throws on invalid measure name.
*/
final public static function create(
string $name,
string $description = "",
string $description = '',
string $unit = Measure::DIMENSIONLESS
): IntMeasure {
return self::registerMeasureHandle($name, $description, $unit);
Expand All @@ -72,7 +72,7 @@ final public function m(int $value): Measurement
* @param Measure $measure The Measure.
* @param int $value The Measurement value.
*/
public function __construct(Measure &$measure, int $value)
public function __construct(Measure $measure, int $value)
{
parent::__construct($measure, $value);
}
Expand Down
16 changes: 8 additions & 8 deletions src/Stats/Measure.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,22 @@ abstract class Measure
use \OpenCensus\Utils\PrintableTrait;

/** measurement is dimensionless */
public const DIMENSIONLESS = "1";
public const DIMENSIONLESS = '1';
/** measurement in bytes */
public const BYTES = "By";
public const BYTES = 'By';
/** measurement in milliseconds */
public const MILLISECONDS = "ms";
public const MILLISECONDS = 'ms';

protected const NAME_MAX_LENGTH = 255;
protected const EX_NAME_EXISTS = "Different Measure Type with same name already exists.";
protected const EX_INVALID_NAME = "Name should be a ASCII string with a length " .
"no greater than " . self::NAME_MAX_LENGTH . " characters.";
protected const EX_NAME_EXISTS = 'Different Measure Type with same name already exists.';
protected const EX_INVALID_NAME = 'Name should be an ASCII string with a length no greater than ' .
self::NAME_MAX_LENGTH . ' characters.';

/**
* Contains our initialized Measure's
* Contains our initialized Measures
* @var array $map
*/
protected static $map = array();
protected static $map = [];
/**
* Holds our Measure's name.
* @var string $name
Expand Down
4 changes: 3 additions & 1 deletion src/Stats/MeasureHandleTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ private static function registerMeasureHandle(string $name, string $description,
$description = $name;
}

/** @var Measure $m */
$m = new self($name, $description, $unit);
Stats::getInstance()->getExporter()->createMeasure($m);
Stats::getExporter()->createMeasure($m);

return parent::$map[$name] = $m;
}
}
2 changes: 1 addition & 1 deletion src/Stats/Measurement.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ abstract class Measurement
* @param Measure $measure The measure this measurement belongs to.
* @param mixed $value The value of the measurement.
*/
protected function __construct(Measure &$measure, $value)
protected function __construct(Measure $measure, $value)
{
$this->m = $measure;
$this->v = $value;
Expand Down
Loading

0 comments on commit 43eeb34

Please sign in to comment.