Skip to content

Commit

Permalink
Properties should be described in class. It's not enough to describe …
Browse files Browse the repository at this point in the history
…them in the constructor

Few phpdoc fixes
Few string escape fixes
There is no "\b" literal in PHP: https://php.net/manual/en/language.types.string.php
setProcessorOptions should be described in parent class because it's called in Raven_Client::setProcessorsFromOptions
Change links to documentations
  • Loading branch information
nokitakaze committed Feb 13, 2017
1 parent abe428f commit 362b11b
Show file tree
Hide file tree
Showing 14 changed files with 184 additions and 20 deletions.
117 changes: 107 additions & 10 deletions lib/Raven/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class Raven_Client
public $breadcrumbs;
public $context;
public $extra_data;
/**
* @var array|null
*/
public $severity_map;
public $store_errors_for_bulk_send = false;

Expand All @@ -43,6 +46,61 @@ class Raven_Client
protected $serializer;
protected $reprSerializer;

/**
* @var string
*/
protected $app_path;
/**
* @var array
*/
protected $prefixes;
/**
* @var array
*/
protected $excluded_app_paths;
/**
* @var Callable
*/
protected $transport;

var $logger;
var $server;
var $secret_key;
var $public_key;
var $project;
var $auto_log_stacks;
var $name;
var $site;
var $tags;
var $release;
var $environment;
var $trace;
var $timeout;
var $message_limit;
var $exclude;
var $http_proxy;
protected $send_callback;
var $curl_method;
var $curl_path;
var $curl_ipv4;
var $ca_cert;
var $verify_ssl;
var $curl_ssl_version;
var $trust_x_forwarded_proto;
var $mb_detect_order;
/**
* @var Raven_Processor[]
*/
var $processors;
/**
* @var string|integer|null
*/
var $_lasterror;
var $_last_event_id;
var $_user;
var $_pending_events;
var $sdk;

public function __construct($options_or_dsn=null, $options=array())
{
if (is_array($options_or_dsn)) {
Expand Down Expand Up @@ -217,11 +275,16 @@ public function setExcludedAppPaths($value)
}
return $this;
}

public function getPrefixes()
{
return $this->prefixes;
}

/**
* @param array $value
* @return $this
*/
public function setPrefixes($value)
{
$this->prefixes = $value ? array_map(array($this, '_convertPath'), $value) : $value;
Expand Down Expand Up @@ -261,14 +324,18 @@ public function getUserAgent()
* and is responsible for encoding the data, authenticating, and sending
* the data to the upstream Sentry server.
*
* @param function $value Function to be called
* @param Callable $value Function to be called
* @return Raven_Client
*/
public function setTransport($value)
{
$this->transport = $value;
return $this;
}

/**
* @return string[]|Raven_Processor[]
*/
public static function getDefaultProcessors()
{
return array(
Expand All @@ -281,12 +348,16 @@ public static function getDefaultProcessors()
* sent to Sentry.
*
* @param $options
* @return array
* @return Raven_Processor[]
*/
public function setProcessorsFromOptions($options)
{
$processors = array();
foreach (Raven_util::get($options, 'processors', self::getDefaultProcessors()) as $processor) {
/**
* @var Raven_Processor $new_processor
* @var Raven_Processor|string $processor
*/
$new_processor = new $processor($this);

if (isset($options['processorOptions']) && is_array($options['processorOptions'])) {
Expand Down Expand Up @@ -349,6 +420,9 @@ public function getLastError()

/**
* Given an identifier, returns a Sentry searchable string.
*
* @param mixed $ident
* @return mixed
*/
public function getIdent($ident)
{
Expand All @@ -357,7 +431,13 @@ public function getIdent($ident)
}

/**
* Deprecated
* @param string $message The message (primary description) for the event.
* @param array $params params to use when formatting the message.
* @param string $level Log level group
* @param boolean|array $stack
* @param mixed $vars
* @return string|null
* @deprecated
*/
public function message($message, $params=array(), $level=self::INFO,
$stack=false, $vars = null)
Expand All @@ -366,7 +446,9 @@ public function message($message, $params=array(), $level=self::INFO,
}

/**
* Deprecated
* @param Exception $exception
* @return string|null
* @deprecated
*/
public function exception($exception)
{
Expand All @@ -379,6 +461,9 @@ public function exception($exception)
* @param string $message The message (primary description) for the event.
* @param array $params params to use when formatting the message.
* @param array $data Additional attributes to pass with this event (see Sentry docs).
* @param boolean|array $stack
* @param mixed $vars
* @return string|null
*/
public function captureMessage($message, $params=array(), $data=array(),
$stack=false, $vars = null)
Expand Down Expand Up @@ -415,6 +500,9 @@ public function captureMessage($message, $params=array(), $data=array(),
*
* @param Exception $exception The Exception object.
* @param array $data Additional attributes to pass with this event (see Sentry docs).
* @param mixed $logger
* @param mixed $vars
* @return string|null
*/
public function captureException($exception, $data=null, $logger=null, $vars=null)
{
Expand Down Expand Up @@ -483,11 +571,12 @@ public function captureException($exception, $data=null, $logger=null, $vars=nul

/**
* Capture the most recent error (obtained with ``error_get_last``).
* @return string|null
*/
public function captureLastError()
{
if (null === $error = error_get_last()) {
return;
return null;
}

$e = new ErrorException(
Expand All @@ -500,6 +589,9 @@ public function captureLastError()

/**
* Log an query to sentry
* @param string|null $query
* @param string $level
* @param string $engine
*/
public function captureQuery($query, $level=self::INFO, $engine = '')
{
Expand Down Expand Up @@ -756,6 +848,10 @@ public function sendUnsentErrors()
}
}

/**
* @param string $data
* @return string|boolean
*/
public function encode(&$data)
{
$message = Raven_Compat::json_encode($data);
Expand Down Expand Up @@ -795,7 +891,8 @@ public function send(&$data)
}

if ($this->transport) {
return call_user_func($this->transport, $this, $data);
call_user_func($this->transport, $this, $data);
return;
}

$message = $this->encode($data);
Expand All @@ -813,7 +910,7 @@ public function send(&$data)
* Send data to Sentry
*
* @param string $url Full URL to Sentry
* @param array $data Associative array of data to log
* @param array|string $data Associative array of data to log
* @param array $headers Associative array of headers
*/
private function send_remote($url, $data, $headers=array())
Expand Down Expand Up @@ -871,7 +968,7 @@ protected function get_curl_options()
* Send the message over http to the sentry url given
*
* @param string $url URL of the Sentry instance to log to
* @param array $data Associative array of data to log
* @param array|string $data Associative array of data to log
* @param array $headers Associative array of headers
*/
private function send_http($url, $data, $headers=array())
Expand Down Expand Up @@ -907,7 +1004,7 @@ protected function buildCurlCommand($url, $data, $headers)
* Send the cURL to Sentry asynchronously. No errors will be returned from cURL
*
* @param string $url URL of the Sentry instance to log to
* @param array $data Associative array of data to log
* @param array|string $data Associative array of data to log
* @param array $headers Associative array of headers
* @return bool
*/
Expand All @@ -921,7 +1018,7 @@ private function send_http_asynchronous_curl_exec($url, $data, $headers)
* Send a blocking cURL to Sentry and check for errors from cURL
*
* @param string $url URL of the Sentry instance to log to
* @param array $data Associative array of data to log
* @param array|string $data Associative array of data to log
* @param array $headers Associative array of headers
* @return bool
*/
Expand Down
11 changes: 8 additions & 3 deletions lib/Raven/Compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function hash_hmac($algo, $data, $key, $raw_output=false)

/**
* Implementation from 'KC Cloyd'.
* See https://nl2.php.net/manual/en/function.hash-hmac.php
* See https://php.net/manual/en/function.hash-hmac.php
*/
public static function _hash_hmac($algo, $data, $key, $raw_output=false)
{
Expand Down Expand Up @@ -66,6 +66,9 @@ public static function _hash_hmac($algo, $data, $key, $raw_output=false)
/**
* Note that we discard the options given to be compatible
* with PHP < 5.3
* @param mixed $value
* @param integer $options
* @return string
*/
public static function json_encode($value, $options=0)
{
Expand All @@ -79,12 +82,14 @@ public static function json_encode($value, $options=0)
/**
* Implementation taken from
* https://www.mike-griffiths.co.uk/php-json_encode-alternative/
* @param mixed $value
* @return string
*/
public static function _json_encode($value)
{
static $jsonReplaces = array(
array('\\', '/', "\n", "\t", "\r", "\b", "\f", '"'),
array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'));
array('\\', '/', "\n", "\t", "\r", "\f", '"'),
array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\f', '\"'));

if (is_null($value)) {
return 'null';
Expand Down
13 changes: 13 additions & 0 deletions lib/Raven/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@
*/
class Raven_Context
{
/**
* @var array
*/
var $tags;
/**
* @var array
*/
var $extra;
/**
* @var array|null
*/
var $user;

public function __construct()
{
$this->clear();
Expand Down
4 changes: 3 additions & 1 deletion lib/Raven/CurlHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ public function join($timeout=null)
} while ($timeout !== 0 && time() - $start < $timeout);
}

// https://se2.php.net/manual/en/function.curl-multi-exec.php
/**
* @doc https://php.net/manual/en/function.curl-multi-exec.php
*/
private function select()
{
do {
Expand Down
14 changes: 14 additions & 0 deletions lib/Raven/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
*/
abstract class Raven_Processor
{
protected $client;
/**
* Raven_Processor constructor.
*
* @param Raven_Client $client
* @codeCoverageIgnore
*/
public function __construct(Raven_Client $client)
{
$this->client = $client;
Expand All @@ -17,4 +24,11 @@ public function __construct(Raven_Client $client)
* @param array $data Array of log data
*/
abstract public function process(&$data);

/**
* Override the default processor options
*
* @param array $options Associative array of processor options
*/
abstract public function setProcessorOptions(array $options);
}
7 changes: 5 additions & 2 deletions lib/Raven/SanitizeDataProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class Raven_SanitizeDataProcessor extends Raven_Processor
const FIELDS_RE = '/(authorization|password|passwd|secret|password_confirmation|card_number|auth_pw)/i';
const VALUES_RE = '/^(?:\d[ -]*?){13,16}$/';

private $client;
private $fields_re;
private $values_re;
protected $session_cookie_name;

public function __construct(Raven_Client $client)
{
$this->client = $client;
parent::__construct($client);
$this->fields_re = self::FIELDS_RE;
$this->values_re = self::VALUES_RE;
$this->session_cookie_name = ini_get('session.name');
Expand Down Expand Up @@ -64,6 +64,9 @@ public function sanitize(&$item, $key)
}
}

/** @noinspection PhpInconsistentReturnPointsInspection
* @param array $data
*/
public function sanitizeException(&$data)
{
foreach ($data['exception']['values'] as &$value) {
Expand Down
Loading

0 comments on commit 362b11b

Please sign in to comment.