notifme/notifme-sdk

View on GitHub
lib/sender.js

Summary

Maintainability
F
3 days
Test Coverage

Function value has 49 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    value: function () {
      var _sendOnEachChannel = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(request) {
        var _this2 = this;
        return _regenerator["default"].wrap(function _callee4$(_context4) {
          while (1) switch (_context4.prev = _context4.next) {
Severity: Minor
Found in lib/sender.js - About 1 hr to fix

    Function _callee4 has 44 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          var _sendOnEachChannel = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(request) {
            var _this2 = this;
            return _regenerator["default"].wrap(function _callee4$(_context4) {
              while (1) switch (_context4.prev = _context4.next) {
                case 0:
    Severity: Minor
    Found in lib/sender.js - About 1 hr to fix

      Function _callee4$ has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              return _regenerator["default"].wrap(function _callee4$(_context4) {
                while (1) switch (_context4.prev = _context4.next) {
                  case 0:
                    return _context4.abrupt("return", _promise["default"].all((0, _keys["default"])(request).filter(function (channel) {
                      return _this2.channels.includes(channel);
      Severity: Minor
      Found in lib/sender.js - About 1 hr to fix

        Function Sender has 38 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          function Sender(channels, providers, strategies) {
            var _this = this;
            (0, _classCallCheck2["default"])(this, Sender);
            this.channels = channels;
            this.providers = providers;
        Severity: Minor
        Found in lib/sender.js - About 1 hr to fix

          Function value has 36 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              value: function () {
                var _send = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(request) {
                  var resultsByChannel, result;
                  return _regenerator["default"].wrap(function _callee2$(_context2) {
                    while (1) switch (_context2.prev = _context2.next) {
          Severity: Minor
          Found in lib/sender.js - About 1 hr to fix

            Function _callee2 has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                  var _send = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(request) {
                    var resultsByChannel, result;
                    return _regenerator["default"].wrap(function _callee2$(_context2) {
                      while (1) switch (_context2.prev = _context2.next) {
                        case 0:
            Severity: Minor
            Found in lib/sender.js - About 1 hr to fix

              Function senders has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  this.senders = (0, _keys["default"])(strategies).reduce(function (acc, channel) {
                    acc[channel] = _this.providers[channel].length > 0 ? strategies[channel](_this.providers[channel]) : ( /*#__PURE__*/function () {
                      var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(request) {
                        var provider;
                        return _regenerator["default"].wrap(function _callee$(_context) {
              Severity: Minor
              Found in lib/sender.js - About 1 hr to fix

                Function channel has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                      acc[channel] = _this.providers[channel].length > 0 ? strategies[channel](_this.providers[channel]) : ( /*#__PURE__*/function () {
                        var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(request) {
                          var provider;
                          return _regenerator["default"].wrap(function _callee$(_context) {
                            while (1) switch (_context.prev = _context.next) {
                Severity: Minor
                Found in lib/sender.js - About 1 hr to fix

                  Function _callee3 has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                                  var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(channel) {
                                    return _regenerator["default"].wrap(function _callee3$(_context3) {
                                      while (1) switch (_context3.prev = _context3.next) {
                                        case 0:
                                          _context3.prev = 0;
                  Severity: Minor
                  Found in lib/sender.js - About 1 hr to fix

                    Function _callee2$ has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                            return _regenerator["default"].wrap(function _callee2$(_context2) {
                              while (1) switch (_context2.prev = _context2.next) {
                                case 0:
                                  _context2.next = 2;
                                  return this.sendOnEachChannel(request);
                    Severity: Minor
                    Found in lib/sender.js - About 1 hr to fix

                      Function _callee3$ has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                                        return _regenerator["default"].wrap(function _callee3$(_context3) {
                                          while (1) switch (_context3.prev = _context3.next) {
                                            case 0:
                                              _context3.prev = 0;
                                              _context3.t0 = _objectSpread;
                      Severity: Minor
                      Found in lib/sender.js - About 1 hr to fix

                        Function _objectSpread has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                        Open

                        function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
                        Severity: Minor
                        Found in lib/sender.js - About 45 mins to fix

                        Cognitive Complexity

                        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                        A method's cognitive complexity is based on a few simple rules:

                        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                        • Code is considered more complex for each "break in the linear flow of the code"
                        • Code is considered more complex when "flow breaking structures are nested"

                        Further reading

                        Similar blocks of code found in 11 locations. Consider refactoring.
                        Open

                        function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
                        Severity: Major
                        Found in lib/sender.js and 10 other locations - About 7 hrs to fix
                        lib/index.js on lines 29..29
                        lib/providers/email/mandrill.js on lines 24..24
                        lib/providers/email/sendgrid.js on lines 26..26
                        lib/providers/email/sparkpost.js on lines 25..25
                        lib/providers/notificationCatcherProvider.js on lines 21..21
                        lib/providers/push/adm.js on lines 23..23
                        lib/providers/push/wns.js on lines 23..23
                        lib/providers/sms/callr.js on lines 23..23
                        lib/providers/sms/clickatell.js on lines 22..22
                        lib/providers/sms/nexmo.js on lines 22..22

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 176.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 12 locations. Consider refactoring.
                        Open

                        function ownKeys(e, r) { var t = _Object$keys2(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
                        Severity: Major
                        Found in lib/sender.js and 11 other locations - About 3 hrs to fix
                        lib/providers/email/mandrill.js on lines 23..23
                        lib/providers/email/sendgrid.js on lines 25..25
                        lib/providers/email/sparkpost.js on lines 24..24
                        lib/providers/notificationCatcherProvider.js on lines 20..20
                        lib/providers/push/adm.js on lines 22..22
                        lib/providers/push/notificationCatcher.js on lines 27..27
                        lib/providers/push/wns.js on lines 22..22
                        lib/providers/sms/callr.js on lines 22..22
                        lib/providers/sms/clickatell.js on lines 21..21
                        lib/providers/sms/nexmo.js on lines 21..21
                        lib/providers/webpush/notificationCatcher.js on lines 27..27

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 95.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        There are no issues that match your filters.

                        Category
                        Status