dprmc/sentry-helper

A tiny library to contain some helper functions needed to interact with Clear Structure's Sentry System.

Maintainers

Package info

github.com/DPRMC/SentryHelper

pkg:composer/dprmc/sentry-helper

Statistics

Installs: 4 532

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.20 2026-06-27 17:11 UTC

README

GitHub release (latest by date) Build Status Codecov Packagist GitHub issues

A small PHP helper library for working with Clear Structure Sentry data inside FIMS integrations.

The package provides static constants, mapping arrays, and utility methods for translating Sentry transaction codes, currency codes, boolean fields, CDS names, and weighted average purchase prices.

Requirements

  • PHP 7.0 or newer
  • Composer

Installation

Install the package with Composer:

composer require dprmc/sentry-helper

Composer autoloads the helper through the DPRMC\FIMS\Helpers namespace:

<?php

require __DIR__ . '/vendor/autoload.php';

use DPRMC\FIMS\Helpers\SentryHelper;

Quick Start

<?php

use DPRMC\FIMS\Helpers\SentryHelper;

$transactionType = SentryHelper::transactionTypeText(SentryHelper::BUY);
// 'Buy'

$fimsBoolean = SentryHelper::translateFieldSentryToFimsBoolean('True');
// true

$slug = SentryHelper::slugifyName('ABC Loan/Series 1');
// 'ABC@Loan~Series@1'

$name = SentryHelper::unslugifyName($slug);
// 'ABC Loan/Series 1'

Public Constants And Mappings

SentryHelper exposes Sentry ids as class constants so code can use named values instead of magic numbers.

SentryHelper::BUY;  // 26
SentryHelper::SELL; // 19
SentryHelper::USD;  // 146

The class also exposes public mapping arrays:

Property Description
SentryHelper::$currencyCodeDescriptions Maps Sentry currency code ids to currency abbreviations, such as 146 => 'USD'.
SentryHelper::$transactionCodeDescriptions Maps Sentry transaction code ids to display names, such as 26 => 'Buy'.
SentryHelper::$transactionCodeTradeActions Maps selected transaction code ids to trade actions: buy, sell, or misc.

API Reference

transactionTypeText(int $transactionCodeId): string

Returns the display text for a Sentry transaction code id.

SentryHelper::transactionTypeText(SentryHelper::BUY);
// 'Buy'

If the transaction code id is not present in SentryHelper::$transactionCodeDescriptions, the method throws an Exception.

SentryHelper::transactionTypeText(99999999);
// throws Exception

translateFieldSentryToFimsBoolean(?string $bool)

Converts a Sentry boolean string into the boolean value expected by FIMS.

SentryHelper::translateFieldSentryToFimsBoolean('True');
// true

SentryHelper::translateFieldSentryToFimsBoolean('false');
// false

SentryHelper::translateFieldSentryToFimsBoolean(null);
// null

Any non-null value other than true, after lowercasing, returns false.

slugifyName(string $name): string

Converts a Sentry name into a reversible slug-safe representation.

SentryHelper::slugifyName('ABC Loan/Series 1');
// 'ABC@Loan~Series@1'

Replacement rules:

Input character Output character
Space @
/ ~

unslugifyName(string $slug): string

Converts a slugified name back into its original representation.

SentryHelper::unslugifyName('ABC@Loan~Series@1');
// 'ABC Loan/Series 1'

prettifyCDSName(string $name): string

Formats a CDS name for display by replacing underscores with spaces.

SentryHelper::prettifyCDSName('CMBX_A_CDSI_S1 1/1_CDS1');
// 'CMBX A CDSI S1 1/1 CDS1'

splitCDSName(string $nameWithLot): array

Splits a CDS name-with-lot string into a display name and lot number.

SentryHelper::splitCDSName('CDX_NA_IG_CDS12');
// [
//     'name' => 'CDX NA IG',
//     'lot' => '12',
// ]

The method treats the final underscore-delimited segment as the lot segment, removes CDS from that segment, and prettifies the remaining name.

wapp($iterable, $quantityField, $priceField)

Calculates weighted average purchase price for rows containing quantity and price fields.

$rows = [
    ['quantity' => 10, 'price' => 99],
    ['quantity' => 20, 'price' => 102],
];

SentryHelper::wapp($rows, 'quantity', 'price');
// 101

If the total quantity is zero, the method returns null.

Development

Install dependencies:

composer install

Run the test suite:

vendor/bin/phpunit

The unit tests cover every public helper method and the public mapping arrays:

  • Transaction code description lookup and unknown-code exception handling
  • Currency, transaction description, and trade action mappings
  • Sentry string boolean conversion, including true, false, null, and unknown strings
  • Name slugging and unslugging for spaces and slashes
  • CDS display-name formatting and lot splitting
  • Weighted average purchase price calculation, including the zero-quantity null path

To generate a coverage report, enable a PHP coverage driver such as Xdebug or PCOV before running PHPUnit. The repository's PHPUnit configuration writes HTML coverage to build/coverage/html and Clover XML to build/logs/clover.xml when a coverage driver is available.

Run a syntax check on the helper:

php -l src/SentryHelper.php

License

This package is released under the MIT License. See LICENSE.